0

I'm talking to an SQL server 2005 using PHP's PDO API:

$mssql = new PDO('dblib:host=foohost;dbname=foodb', 'foouser', 'foopassword');

Subsequently, I want to backup the database to a local file as shown in the code below - which then fails.

$query = "
    BACKUP DATABASE foodb
        TO DISK = 'D:\\migration\\test_backup.bak';
    GO
";
$stmt = $mssql->prepare($query);
$stmt->execute();

The error I'm getting is this (result from $stmt->errorInfo()):

[0] => HY000
[1] => 102
[2] => General SQL Server error: Check messages from the SQL Server [102] (severity 15) [(null)]
[3] => -1
[4] => 15

I've tried to do the same thing using SQL Server Management Studio, and the exact same query works. So - any hints on how I could get this to work (Note: I'm forced to use PHP on a remote linux host, so any local windows tools won't work)

Dave Vogt
  • 18,600
  • 7
  • 42
  • 54
  • Did you try putting the command in a stored procedure, and calling the stored procedure from PHP? – Aaron Bertrand Sep 25 '12 at 16:08
  • @AaronBertrand, As far as I understand, this would only shift the problem to the creation of said procedure. It won't be possible to automate. However I'll look into it. – Dave Vogt Sep 25 '12 at 16:18
  • Well you can pass any arguments you want into the stored procedure. You might get a more meaningful error message, or you might actually avoid the error altogether if it's breaking because PDO has no idea how parse a backup command... – Aaron Bertrand Sep 25 '12 at 16:25

0 Answers0