Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

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

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=localhostSQLEXPRESS;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
";

$backfile = 'C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBackupsql server bk' ;
echo "Connected to SQL Server
";
$backfile = 'C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBackupsql 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 FilesMicrosoft SQL ServerMSSQL.1MSSQLBackupsql 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...