SQL Server:使用PHP处于“还原"状态的数据库 [英] SQL Server: Database stuck in “Restoring” state with PHP

查看:108
本文介绍了SQL Server:使用PHP处于“还原"状态的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按照 SQL Server:中的说明备份数据库在恢复"中状态.但是我的数据库卡在了恢复"状态.下面的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=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);

运行此代码后,我的child_database停留在还原状态.但是我复制了sql命令

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

并在Microsoft sql服务器管理工​​具中运行,效果很好.

and run in microsoft sql server management tool it works just fine.

我尝试运行添加php代码

I try to run add php code

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

我有一个例外.

请帮助.

推荐答案

PDO驱动程序似乎有问题,此问题可能在构建驱动程序的ODBC/SNAC层中.但是此数据库还原可与其他驱动程序很好地配合. 我尝试使用sqlsrv和mssql,它们运行良好. 有关更多详细信息,请参见从PHP恢复SQL Server数据库

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

这篇关于SQL Server:使用PHP处于“还原"状态的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆