Page 1 of 1

using PDO to send a BACKUP statement to MSSQL

Posted: Wed Sep 05, 2007 11:23 pm
by ocpaul20
Windows XP
IIS
PHP 5.2.3
MSSQL Server 2005 Express

I am having a problem using PDO to send a BACKUP statement to MSSQL.

This statement runs perfectly well in MSSQL 2005 Management Studio Express in the query window.
It just wont run from PHP. Maybe I am doing something wrong?

Can anyone help please?

returns a zero from the var_dump($rcount) below and it gives the success message but no file is produced.
Thanks,
Paul

Code: Select all

$dbuser = "xxxxx";
	$dbpass = "xxxxx";

	try {
                $dbh = new PDO('mssql:host=\\\\.\pipe\\MSSQL$SQLEXPRESS\\sql\\query;dbname=project13', $dbuser, $dbpass); 

	} catch (PDOException $e) {
	   	print "<BR>(1)Error!: " . $e->getMessage() . "<br/>";
	   	exit;
	}

	$query = "BACKUP DATABASE [project13] TO  DISK = N'project_backup.bak' WITH NOFORMAT,
	 NOINIT,  NAME = N'This is a full project backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10;";
	try
	{
		$rcount = $dbh->exec($query);

		var_dump($rcount);
		// var dump is zero, not false.

	} catch (PDOException $e) {
		error_log ("Backup failed: ".$query);
		die(" Problem with Backup query statement $query");
	}

	echo "Database backed up!";
	echo "<BR>========= end =============<BR>";
	exit;

Posted: Thu Sep 06, 2007 7:46 am
by Begby
Perhaps you should edit your post and remove your login credentials.

Posted: Thu Sep 06, 2007 2:37 pm
by John Cartwright
Begby wrote:Perhaps you should edit your post and remove your login credentials.
Done.

Posted: Thu Sep 06, 2007 6:37 pm
by ocpaul20
thankyou. I agree that we should not put loging stuff here, however I did change them because you never know who's looking, do you?

Anyone any info on this BACKUP problem please ? Someone must have done this before, surely?