SQL Server: Database stuck in “Restoring” state with PHP

扶醉桌前 提交于 2019-12-02 07:22:17

问题


I tried to backup my database following the instruction from SQL Server: Database stuck in "Restoring" state. but i have my database stuck in "Restoring" state. php code 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_database stuck in restoring 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 just fine.

I try to run add php code

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

I got an exception.

please help.


回答1:


It seems have problem with PDO driver, this problem may be in the ODBC/SNAC layer on which the driver is built. But this database restoring works well with other drivers. I tried with sqlsrv and mssql, they worked well. For more detail, see Restoring a SQL Server Database from PHP



来源:https://stackoverflow.com/questions/9050799/sql-server-database-stuck-in-restoring-state-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!