|
|
The following methods are available to database handles, statement handles, and driver handles. They are mostly used for error handling.
$rv = $h->err;
Returns the native error code from the last method (usually an integer).
$error_string = $dbh->errstr;
Returns an error string from the failure of the previous call.
For example:
my $hostname = 'localhost'; my $database = 'firstdb'; my $username = 'guru2b'; my $password = 'g00r002b'; #Connect to the database my $dbh = DBI->connect("dbi:mysql:$database:$hostname", $username,– $password) or die $DBI::errstr;
$h->func(@func_arguments, $func_name);
Used to call other nonstandard driver methods. This takes an array of arguments and the method name as arguments.
This does not trigger the usual error detection mechanisms (such as RaiseError or PrintError) or clear a previous error (such as $DBI::err or $DBI::errstr).
$rv = $h->set_err($err, $errstr [, $state, $method [, $rv]]);
A new method mainly used by DBI drivers and subclasses. It sets the err, errstr, and state values for the handle (to enable error handling through RaiseError and so on).
$method sets a more useful method name for the error string, and $rv sets a return value (usually undef).
For example:
sub doodle { # … try to 'doodle' or return $sth->set_err(1234, "Nope. Sorry. Out of luck. It all– went wrong", undef, "doodle"); }
$rv = $h->state;
Returns an error code in SQLSTATE format. Usually returns the general S1000 code when the driver does not support SQLSTATE.
trace($trace_level [, $trace_filename])
See the earlier trace method.
$h->trace_msg($message_text [, $minimum_level]);
If tracing is enabled, outputs the message text to the trace file. If the minimum level is set (default 1), this only outputs the message if the trace level is at least that level.
|
|