Collections:
mssql_get_last_message() - Retrieving Error Messages
How To Retrieve Error Messages using mssql_get_last_message()?
✍: Guest
When you call mssql_query() to execute a SQL statement, and the execution failed on the SQL Server, you can use mssql_get_last_message() function to retrieve the error messages.
The tutorial script below shows you a good example:
<?php
$con = mssql_connect('LOCALHOST','sa','FYIcenter');
mssql_select_db('FyiCenterData', $con);
# dropping a table
$sql = 'DROP TABLE fyi.center';
$res = mssql_query($sql, $con);
if (!$res) {
print("Execution failed:\n");
print(" Error: ".mssql_get_last_message()."\n");
} else {
print("Execution was successful.\n");
}
mssql_close($con);
?>
If you run this script for the first time, you will get this output:
Execution was successful.
If you run this script again, the SQL statement will fail on the SQL Server, and you will get:
Warning: mssql_query(): message: Cannot drop the table 'fyi.center', because it does not exist or you do not have permission. (severity 11) in C:\test\fyi-center.php on line 7 Execution failed: Error: Cannot drop the table 'fyi.center', because it does not exist or you do not have permission.
⇒ Turning Off PHP Warning Messages for MSSQL Connection
⇐ mssql_query() - Executing SQL Statements
⇑ SQL Server FAQs - PHP MSSQL Functions - Connections and Query Execution
2024-04-07, 2107🔥, 0💬
Popular Posts:
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL? Random numbers a...
How To Start the Command-Line SQL*Plus in Oracle? If you Oracle server or client installed on your w...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
How To Revise and Re-Run the Last SQL Command in Oracle? If executed a long SQL statement, found a m...
What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema in Oracle? For a us...