Name

mysql_error

Synopsis

string mysql_error([cresource connection])

Returns the text of the error message associated with the most recently executed MySQL function or '' (the empty string) if no error occurred. An optional connection can be supplied; otherwise, the most recently opened connection resource handle that is still open is used. Any successful MySQL-related function call resets the text to '' (the empty string), with the exceptions of mysql_error( ) and mysql_errno( ), which do not change this value.

Example

<?php
  $connection = mysql_connect("localhost", "fred", "shhh");
  
  mysql_select_db("not-a-database", $connection);
  
  // Prints MySQL reported error: Unknown database 'not-a-database'
  if (mysql_errno(  ))
     echo "MySQL reported error: " . mysql_error(  );
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.