Publisher's description
DBI DBD:: MySQL is a Perl module with MySQL driver for the Perl5 Interface (DBI). DBD:: MySQL is a Perl module with MySQL driver for the Perl5 Interface (DBI). SYNOPSIS use DBI; $ dsn = "DBI: mysql: database = $ database; host = $ hostname, port = $ port" $ dbh = DBI-> connect (HRD database $ dsn, $ user, $ password); $ = DBI-> install_driver ( "mysql"); @ databases = DBI-> data_sources ( "mysql") or @ = DBI-> data_sources ( "mysql", ( "host" => $ host, "port "=> $ port)); $ sth = $ dbh-> prepare (" SELECT * FROM foo WHERE bla ") or $ sth = $ dbh-> prepare (" ListFields $ table ") or $ sth = $ dbh -> prepare ( "ListIndex $ table $ index"); $ sth-> execute; $ numRows = $ sth-> rows; numFields $ = $ sth-> ( 'NUM_OF_FIELDS'); $ sth-> finish; drh $ rc = $ -> func ( 'createdb', $ base, $ host, $ user, $ password, 'admin'); drh $ rc = $ -> func ( 'dropdb', $ base, $ host, $ user, $ password, 'admin'); drh $ rc = $ -> func ( 'shutdown', $ host, $ user, $ password, 'admin'); rc = $ drh $> func ( 'reload', $ host, $ user, $ password, 'admin') $ dbh = $ rc -> func ( 'createdb', $ database, 'admin') $ dbh = $ rc -> func ( 'dropdb', $ database, 'admin' ) $ dbh = $ rc -> func ( 'shutdown', 'admin') $ dbh = $ rc -> func ( 'reload', 'admin'); EXAMPLE #! / Usr / bin / perl use strict; use DBI () # Connect to the database. my $ dbh = DBI-> connect ( "DBI: mysql: database = test; host = localhost", "Joe," password "Joe" ( 'RaiseError' => 1)) drop table # foo '. This may fail if "foo" does not exist. # So, we put an eval around it. eval ($ dbh-> do ( "DROP TABLE foo")) print "Dropping foo failed: $ @ n" if $ @; foo # Create a new table '. This must not fail, so we do not # catch errors. $ Dbh-> do ( "CREATE TABLE foo (id INTEGER, name VARCHAR (20 ))"); # insert data into 'foo'. We use $ dbh-> quote () to quote the name. $ Dbh-> do ( "INSERT INTO foo VALUES (1,". $ Dbh-> quote ( "Tim"). ")"); # Same thing, but using placeholders $ dbh-> do ( "INSERT INTO (?,?) foo ", undef, 2," Jochen ") # Now retrieve data on the table. my $ sth = $ dbh-> prepare ( "SELECT * FROM foo"); $ sth-> execute () while (my $ sth = $ ref-> fetchrow_hashref ()) (print "Found a row: id = $ ref-> ( 'id') name = $ ref-> ( 'name') n ";) $ sth-> finish () # Disconnect from the database. $ Dbh-> disconnect (); DBD:: MySQL is the Perl5 Database Interface driver for the MySQL database. In other words: DBD:: MySQL is an interface between the Perl programming language and the MySQL programming API that comes with the relational database management system MySQL. Most functions provided by this programming API are supported. Some rarely used functions are missing, mainly because nobody has ever requested.