SQL Server: Database stuck in "Rebuild" state with PHP

I tried to create a backup of my database according to the SQL Server instruction : Database is stuck in a "Restore" state . but my database is stuck in "Restore" state. php below:

$database = "container";
$uid = "sa";
$pwd = "12345" ; 

try {
      $conn = new PDO( "sqlsrv:Server=localhost\SQLEXPRESS;Database=$database", 
          $uid, 
          $pwd
          //,array(PDO::ATTR_PERSISTENT => true)
          ); 
  $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); }
catch( PDOException $e ) {
  die( "Error connecting to SQL Server" ); }

echo "Connected to SQL Server\n";

$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' ;
echo "Connected to SQL Server\n";
$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk'  ;

$query = "RESTORE DATABASE child_database FROM DISK = '$backfile' WITH  REPLACE, RECOVERY ";
$conn->exec($query);

      

After running this code, I got my child_date stuck in a recovery state. However, I copy the sql command

RESTORE DATABASE child_database FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' WITH  REPLACE, RECOVERY

      

and run in Microsoft SQL Server Management Tool, it works fine.

I am trying to run add php code

$conn->exec("RESTORE DATABASE child_database WITH RECOVERY");

      

I have an exception.

Please, help.

+1


source to share


1 answer


It seems to be a problem with the PDO driver, this problem could be in the ODBC / SNAC layer the driver is built on. But this database recovers well with other drivers. I tried with sqlsrv and mssql, they worked well. For more details see Recovering SQL Server Database from PHP



+2


source







All Articles