$sth = $dbh->prepare("SELECT * FROM foo WHERE bla");
$sth->execute;
$numRows = $sth->rows;
$numFields = $sth->{'NUM_OF_FIELDS'};
$sth->finish;
=head1 EXAMPLE
#!/usr/bin/perl
use strict;
use DBI;
# Connect to the database.
my $dbh = DBI->connect("dbi:mysqlPP:database=test;host=localhost",
"joe", "joe's password",
{'RaiseError' => 1});
# Drop table 'foo'. This may fail, if 'foo' doesn't exist.
# Thus we put an eval around it.
eval { $dbh->do("DROP TABLE foo") };
print "Dropping foo failed: $@\n" if $@;
# Create a new table 'foo'. This must not fail, thus we don't
# catch errors.
$dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");
# INSERT some data into 'foo'. We are using $dbh->quote() for
# quoting the name.
$dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");
# Same thing, but using placeholders
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");
# Now retrieve data from the table.
my $sth = $dbh->prepare("SELECT id, name FROM foo");
$sth->execute();
while (my $ref = $sth->fetchrow_arrayref()) {
print "Found a row: id = $ref->[0], name = $ref->[1]\n";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
=head1 DESCRIPTION
DBD::mysqlPP is a Pure Perl client interface for the MySQL database. This module implements network protool between server and client of MySQL, thus you don't need external MySQL client library like libmysqlclient for this module to work. It means this module enables you to connect to MySQL server from some operation systems which MySQL is not ported. How nifty!
From perl you activate the interface with the statement
use DBI;
After that you can connect to multiple MySQL database servers
and send multiple queries to any of them via a simple object oriented
interface. Two types of objects are available: database handles and
statement handles. Perl returns a database handle to the connect
The hostname, if not specified or specified as '', will default to an
MySQL daemon running on the local machine on the default port
for the INET socket.
=item port
Port where MySQL daemon listens to. default is 3306.
=back
=back
=head2 MetaData Method
=over 4
=item B<tables>
@names = $dbh->tables;
Returns a list of table and view names, possibly including a schema prefix. This list should include all tables that can be used in a "SELECT" statement without further qualification.
=back
=head2 Private MetaData Methods
=over 4
=item ListDBs
@dbs = $dbh->func('_ListDBs');
Returns a list of all databases managed by the MySQL daemon.
=item ListTables
B<WARNING>: This method is obsolete due to DBI's $dbh->tables().
@tables = $dbh->func('_ListTables');
Once connected to the desired database on the desired mysql daemon with the "DBI-"connect()> method, we may extract a list of the tables that have been created within that database.
"ListTables" returns an array containing the names of all the tables present within the selected database. If no tables have been created, an empty list is returned.
@tables = $dbh->func('_ListTables');
foreach $table (@tables) {
print "Table: $table\n";
}
=back
=head1 DATABASE HANDLES
The DBD::mysqlPP driver supports the following attributes of database
handles (read only):
$insertid = $dbh->{'mysqlpp_insertid'};
$insertid = $dbh->{'mysql_insertid'};
=head1 STATEMENT HANDLES
The statement handles of DBD::mysqlPP support a number
of attributes. You access these by using, for example,
my $numFields = $sth->{'NUM_OF_FIELDS'};
=over
=item mysqlpp_insertid/mysql_insertid
MySQL has the ability to choose unique key values automatically. If this
happened, the new ID will be stored in this attribute. An alternative
way for accessing this attribute is via $dbh->{'mysqlpp_insertid'}.
(Note we are using the $dbh in this case!)
=item NUM_OF_FIELDS
Number of fields returned by a I<SELECT> statement. You may use this for checking whether a statement returned a result.
A zero value indicates a non-SELECT statement like I<INSERT>, I<DELETE> or I<UPDATE>.
=back
=head1 INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
=head1 SUPPORT OPERATING SYSTEM
This module has been tested on these OSes.
=over 4
=item * MacOS 9.x
with MacPerl5.6.1r.
=item * MacOS X
with perl5.6.0 build for darwin.
=item * Windows2000
with ActivePerl5.6.1 build631.
=item * FreeBSD 3.4 and 4.x
with perl5.6.1 build for i386-freebsd.
with perl5.005_03 build for i386-freebsd.
=back
=head1 DEPENDENCIES
This module requires these other modules and libraries:
DBI
Net::MySQL
B<Net::MySQL> is a Pure Perl client interface for the MySQL database.
B<Net::MySQL> implements network protool between server and client of
MySQL, thus you don't need external MySQL client library like
libmysqlclient for this module to work. It means this module enables
you to connect to MySQL server from some operation systems which MySQL
is not ported. How nifty!
=head1 DIFFERENCE FROM "DBD::mysql"
The function of B<DBD::mysql> which cannot be used by B<DBD::mysqlPP> is described.