Collections:
Retrieving Execution Error Message in MySQL
How To Get MySQL Statement Execution Errors in MySQL?
✍: FYIcenter.com
When you execute a MySQL statement with mysql_query(), and the statement failed, mysql_query() will return the Boolean value FALSE. This is good enough to tell that there is something wrong with that statement. But if you want to know more about the cause of the failure, you can use mysql_errno() and mysql_error() get the error number and error message. The tutorial exercise below shows you an improved version of the previous PHP script:
<?php
$con = mysql_connect('localhost:8888', 'guest', 'pub');
$sql = 'CREATE DATABASE fyicenter';
if (mysql_query($sql, $con)) {
print("Database fyicenter created.\n");
} else {
print("Database creation failed with error:\n");
print(mysql_errno($con).": ".mysql_error($con)."\n");
}
mysql_close($con);
?>
If you run this script, you will get something like this:
Database creation failed with error: 1044: Access denied for user 'guest'@'%' to database 'fyicenter'
⇒ Deleting an Existing Database in MySQL
⇐ Failed to Create a Database in MySQL
2017-10-23, 3086🔥, 0💬
Popular Posts:
How REAL and FLOAT Literal Values Are Rounded in SQL Server Transact-SQL? By definition, FLOAT(n) sh...
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...
What Are the Basic Features of a Trigger in SQL Server? Since a SQL Server trigger is a really an ev...
How To Start MySQL Server in MySQL? If you want to start the MySQL server, you can run the "mysqld" ...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...