How To Retrieve Error Messages using mssql_get_last_message()?
Submitted by: AdministratorWhen 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','GlobalGuideLine');
mssql_select_db('GlobalGuideLineDatabase', $con);
# dropping a table
$sql = 'DROP TABLE fyi.center';
$res = mssql_query($sql, $con);
if (!$res) {
print("Execution failed: ");
print(" Error: ".mssql_get_last_message()." ");
} else {
print("Execution was successful. ");
}
mssql_close($con);
?>
Submitted by: Administrator
The tutorial script below shows you a good example:
<?php
$con = mssql_connect('LOCALHOST','sa','GlobalGuideLine');
mssql_select_db('GlobalGuideLineDatabase', $con);
# dropping a table
$sql = 'DROP TABLE fyi.center';
$res = mssql_query($sql, $con);
if (!$res) {
print("Execution failed: ");
print(" Error: ".mssql_get_last_message()." ");
} else {
print("Execution was successful. ");
}
mssql_close($con);
?>
Submitted by: Administrator
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
'globalguideline', because it does not exist or you do not
have permission. (severity 11) in C: estglobalguideline.php
on line 7
Execution failed:
Error: Cannot drop the table 'fyi.center', because
it does not exist or you do not have permission.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Convert Binary Strings into Integers in MS SQL Server? |
☺ | What Happens If NULL Values Are Involved in Bitwise Operations? |
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | Does Index Slows Down INSERT Statements? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |