The Mysql.pm API is identical to the Msql API (with "Msql" replaced with "Mysql" in all places) except for the following differences.
Mysql::connect |
$db = Mysql->connect($host, $database, $user, $password); |
use Mysql; $db = Mysql->connect(undef,'mydata','webuser','super_secret_squirrel'); # The database handle is now connected to the local MySQL server using the # database 'mydata'. The user name 'webuser' was used to connect who had # the password 'super_secret_squirrel'.
Mysql::errno |
$error_number = $db->errno; |
use Mysql; my $db = Mysql->connect(undef,'mydata','webuser','super_secret_squirrel'); # There is a parse error in this query... my $output = $db->query('SELECT * from mydata'); if (not $output) { print "Error " . $output->errno . ": " . $output->errmsg . "\n"; }
Mysql::FIELD_TYPE_* |
In addition to the Mysql::TYPE_* datatype functions that are identical to the Msql::TYPE_* functions, Mysql.pm provides these extra datatype functions: |
&Mysql::FIELD_TYPE_BLOB
&Mysql::FIELD_TYPE_CHAR
&Mysql::FIELD_TYPE_DECIMAL
&Mysql::FIELD_TYPE_DATE
&Mysql::FIELD_TYPE_DATETIME
&Mysql::FIELD_TYPE_DOUBLE
&Mysql::FIELD_TYPE_FLOAT
&Mysql::FIELD_TYPE_INT24
&Mysql::FIELD_TYPE_LONGLONG
&Mysql::FIELD_TYPE_LONG_BLOB
&Mysql::FIELD_TYPE_LONG
&Mysql::FIELD_TYPE_MEDIUM_BLOB
&Mysql::FIELD_TYPE_NULL
&Mysql::FIELD_TYPE_SHORT
&Mysql::FIELD_TYPE_STRING
&Mysql::FIELD_TYPE_TIME
&Mysql::FIELD_TYPE_TIMESTAMP
&Mysql::FIELD_TYPE_TINY_BLOB
&Mysql::FIELD_TYPE_VAR_STRING
use Mysql; my $db = Mysql->connect(undef,'mydata'); my $output = $db->query("SELECT name, data from myothertable"); if ($output->type->[0] = &Mysql::FIELD_TYPE_STRING) { print "Name is a STRING.\n"; }
Mysql::Statement::affectedrows |
$number_of_affected_rows = $statement_handle->affectedrows; |
use Mysql; my $db = Mysql->connect(undef,'mydata'); my $output = $db->query("UPDATE mytable set name='bob' where name='joe'"); print $output->affectedrows . " rows were updated.\n";
Mysql::Statement::info |
$info = $sth->info; |
use Mysql; $db = Mysql->connect(undef,'mydata'); my $output = $db->query("LOAD DATA INFILE 'mydata.dat' INTO TABLE mytable"); my $info = $output->info($output); print "LOAD DATA result: $info\n";
Mysql::Statement::insertid |
$new_id = $statement_handle->insertid; |
use Mysql; my $db = Mysql->connect(undef,'mydata'); my $output = $db->query( "INSERT into mytable (id, name, date) VALUES ('','bob','today')"; my $new_id = $output->insertid; print "Bob was entered with an ID number of $new_id.\n";
Mysql::Statement::isblob |
@blobs = $statement_handle->isblob; |
use Mysql; $db = Mysql->connect(undef,'mydata'); my $output = $db->query('SELECT name, data from myothertable'); if ($output->isblob->[0]) { print "Name is a BLOB.\n"; } else { print "Name is not a BLOB.\n"; }
Mysql::query |
use Mysql; my $db = Mysql->connect(undef,'mydata'); my $output = $db->query("UPDATE mytable set name='joe' where name='bob'"); # $output is a statement handle.
Copyright © 2001 O'Reilly & Associates. All rights reserved.
This HTML Help has been published using the chm2web software. |