The mysql_error() function is used to get error message in text format from the last mysql function, or empty string if no error occurred.
PHP mysql_error() Function Example:
The mysql_error() function is used to get error message in text format from the last mysql function, or empty string if no error occurred.
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ mysql_select_db("NOT_Selected", $connection); if (!mysql_query("SELECT * FROM user", $connection)) { echo mysql_error($connection) . "\n"; } } ?>
In this example we have used "NOT_Selected" database that is not exist in the localhost database server. Now we will execute this example and see the output on the browser.
Output:
No database selected
[ 0 ] Comments