dtwxmn8741 2017-11-05 20:27
浏览 56

SQL Server:数据库仅在PHP中处于“恢复”状态

When I restore a database with the SQL Server Management Studio it works just fine.
But when I restore it from the php ( using the function sqlsrv_query ), the database gets stuck on "Restoring..." state.

The sql query I use is this one:

RESTORE DATABASE WEB FROM DISK = 'C:\Program Files (x86)\Zend\Apache24\htdocs\db\WEB.bak' WITH REPLACE,RECOVERY

I also tried to login with the SQL Server Authentication mode using the same user I use with the php ( on sqlsrv_connect ) and to execute the same query, it worked. Only PHP does the problem.

PHP Code:

<?php
$connection_info = array( "Database" => "master", "UID" => "sa", "PWD" => "workingpw" );
$sql_handle = sqlsrv_connect( "DESKTOP\SQLEXPRESS", $connection_info );
if( !$sql_handle ) die();
sqlsrv_configure( "WarningsReturnAsErrors", 0 );

sqlsrv_query($sql_handle, "RESTORE DATABASE WEB FROM DISK = '" . getcwd() . "\\db\\WEB.bak' WITH REPLACE,RECOVERY");
$stmt = sqlsrv_query($sql_handle, "USE WEB");

if($stmt === false)
{
    die(print_r(sqlsrv_errors())); 
}
else echo "Success!";
?>


After PHP execution the error
"[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Database 'WEB' cannot be opened. It is in the middle of a restore." occurs. Restoring state

Please help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看