PHP mysql_error() Function Example

PHP mysql_error() Function Example


Posted in : PHP Posted on : February 7, 2011 at 4:49 PM Comments : [ 0 ]

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

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics