I have a script in PHP with sqlsrv, which connects to a SQL Server 2016 database, and executes SQL queries and retrieves results. Up to here, no problem. But if I try to execute a DBCC CHECKIDENT ($Table, RESEED, $NextIdentity) or a BACKUP DATABASE, as soon as the command "prints" something, the function sqlsrv_query returns, and returns FALSE. Example:
sqlsrv_query( "BACKUP DATABASE MYDB TO DISK = 'C:\\Backup\\MYDB.bak'" );
The sqlsrv_query returns FALSE, and sqlsrv_errors contains:
Array
(
[0] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 3211
[code] => 3211
[2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]10 percent processed.
[message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]10 percent processed.
)
)
For some DBCC commands, it is possible to use them specifying "WITH TABLERESULTS", which would solve the problem, but the specific DBCC that I need does not support that.
Ideally I would like a solution that is synchronous (for instance, waits the end of the backup before returning) and that allows me to check if the DBCC or BACKUP operation was successful.