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.