DBI Methods Common to All Handles

The following methods are available to database handles, statement handles, and driver handles. They are mostly used for error handling.

err

$rv  = $h->err;

Returns the native error code from the last method (usually an integer).

errstr

$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;

func

$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).

set_err

$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"); }

state

$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($trace_level [, $trace_filename])

See the earlier trace method.

trace_msg

$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.



Mastering MySQL 4
Mastering MySQL 4
ISBN: 0782141625
EAN: 2147483647
Year: 2003
Pages: 230
Authors: Ian Gilfillan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net