Database Reference
In-Depth Information
$dbh -> query ( "SELECT" ); # malformed query
}
catch ( PDOException $e )
{
print ( "Cannot execute query \n " );
print ( "Error information using exception object: \n " );
print ( "SQLSTATE value: " . $e -> getCode () . " \n " );
print ( "Error message: " . $e -> getMessage () . " \n " );
print ( "Error information using database handle: \n " );
print ( "Error code: " . $dbh -> errorCode () . " \n " );
$errorInfo = $dbh -> errorInfo ();
print ( "SQLSTATE value: " . $errorInfo [ 0 ] . " \n " );
print ( "Error number: " . $errorInfo [ 1 ] . " \n " );
print ( "Error message: " . $errorInfo [ 2 ] . " \n " );
}
Python
Python signals errors by raising exceptions, and Python programs handle errors by
catching exceptions in the except clause of a try statement. To obtain MySQL-specific
error information, name an exception class, and provide a variable to receive the in‐
formation. Here's an example:
conn_params = {
"database" : "cookbook" ,
"host" : "localhost" ,
"user" : "baduser" ,
"password" : "badpass"
}
try :
conn = mysql . connector . connect ( ** conn_params )
print ( "Connected" )
except mysql . connector . Error as e :
print ( "Cannot connect to server" )
print ( "Error code: %s " % e . errno )
print ( "Error message: %s " % e . msg )
print ( "Error SQLSTATE: %s " % e . sqlstate )
If an exception occurs, the errno , msg , and sqlstate members of the exception object
contain the error number, error message, and SQLSTATE values, respectively. Note that
access to the Error class is through the driver module name.
Java
Java programs handle errors by catching exceptions. To do the minimum amount of
work, print a stack trace to inform the user where the problem lies:
try
{
/* ... some database operation ... */
Search WWH ::




Custom Search