mysql_error([link_identifier])

Description: Returns the error message text from the previous MySQL operation, or the empty string if no error occurred.

Example:

if ($result = mysql_query ("select * from bad_table")) {
    # query worked okay, keep going
} else {
    echo "A database error occurred!<BR>\n";
    echo mysql_error() ." (error no. ". mysql_errno() .")<BR>\n";
    exit;
}

See also: mysql_errno()

Get Sams Teach Yourself MySQL in 21 Days, Second 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.