|
MySQL Chapter Seven (The MySQL DBD perl API)Documentation Version: 0.95 The MySQL DBD Perl Driver(At present this is only a slightly warmed over version of the standard POD style documentation run through pod2html. -mke)SUMMARY: use DBI; $dbh=DBI->connect($host,$database,$user,'mysql'[,$password]); # or $dbh = DBI->connect( '', '', '', 'mysql', { hostname => "localhost", port => 3333, database => "test", username => "myname", password => "mypassword", }); EXAMPLE: #!/usr/bin/perl use DBI; $drh = DBI->install_driver('mysql'); $dbh=$drh->connect('','test','','') or die "Error connecting to database"; $dbh->do("DROP TABLE foo"); $dbh->do("CREATE TABLE foo (Field_1 VARCHAR(60))"); $count = 1; while ($count < 500) { $sth = $dbh->prepare("INSERT INTO foo VALUES('XXXYYYZZZ')"); $sth->execute; $sth->finish; # It is VERY important to call finish, otherwise # you will loose the memory. print "$count\n" unless $count % 10; $count = $count + 1; } $host can be a simple hostname (``db.domain.com'') or a hostname and port (``db.domain.com:3333''). $database is the name of the database to connect to. $user is the username to connect as (leave this blank to connect as the username corresponding to the process' effective uid). $password is optional and should only be specified for accounts that have non blank passwords. The hash keys which DBD::mysql uses are:
You can enable debugging by setting the environment variable
The following tags are supported:
To get the value of an
$id = $dbh->func("_InsertID");
You can use the following work arounds. First of all, always treat values that may be large as strings. As long as you do this they can be displayed and re-inserted into a database without incident. The same goes for inserting new values into tables. If you set a variable called $tmpvar to be equal to "4147483647" and then INSERT it into your database you should be fine. Note that the ""'s are important here. If you need to do calculations involving large numbers you should do them via the initial SELECT.
Escaping Binary StringsIn order to insert binary data into the database you will have to escape certain characters. You may use the following method.
$mystring = $dbh->quote($rawstring);
AUTHORMsqlperl is copyright (C)1997 Alligator Descartes. Modified to Msqlperl by Michael 'Monty' Widenius. All such changes are in public domain. The pod documentation, that was the basis for this chapter and_InsertID by Nathan Torkington.
SEE ALSODBI(3) for information on the use of DBD/DBI.http://www.hermetica.com/technologia/perl/DBI/ for DBI information, http://www.tcx.se/ for mysql information, http://www.hughes.com.au/for msql information.
|
|||||||||||||||||
With any suggestions or questions please feel free to contact us |