.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "DBD::mysql 3" .TH DBD::mysql 3 "2015-07-20" "perl v5.12.5" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBD::mysql \- MySQL driver for the Perl5 Database Interface (DBI) .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use DBI; \& \& $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; \& \& $dbh = DBI\->connect($dsn, $user, $password); \& \& \& $drh = DBI\->install_driver("mysql"); \& @databases = DBI\->data_sources("mysql"); \& or \& @databases = DBI\->data_sources("mysql", \& {"host" => $host, "port" => $port, "user" => $user, password => $pass}); \& \& $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\->{\*(AqNUM_OF_FIELDS\*(Aq}; \& $sth\->finish; \& \& $rc = $drh\->func(\*(Aqcreatedb\*(Aq, $database, $host, $user, $password, \*(Aqadmin\*(Aq); \& $rc = $drh\->func(\*(Aqdropdb\*(Aq, $database, $host, $user, $password, \*(Aqadmin\*(Aq); \& $rc = $drh\->func(\*(Aqshutdown\*(Aq, $host, $user, $password, \*(Aqadmin\*(Aq); \& $rc = $drh\->func(\*(Aqreload\*(Aq, $host, $user, $password, \*(Aqadmin\*(Aq); \& \& $rc = $dbh\->func(\*(Aqcreatedb\*(Aq, $database, \*(Aqadmin\*(Aq); \& $rc = $dbh\->func(\*(Aqdropdb\*(Aq, $database, \*(Aqadmin\*(Aq); \& $rc = $dbh\->func(\*(Aqshutdown\*(Aq, \*(Aqadmin\*(Aq); \& $rc = $dbh\->func(\*(Aqreload\*(Aq, \*(Aqadmin\*(Aq); .Ve .SH "EXAMPLE" .IX Header "EXAMPLE" .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& use DBI; \& \& # Connect to the database. \& my $dbh = DBI\->connect("DBI:mysql:database=test;host=localhost", \& "joe", "joe\*(Aqs password", \& {\*(AqRaiseError\*(Aq => 1}); \& \& # Drop table \*(Aqfoo\*(Aq. This may fail, if \*(Aqfoo\*(Aq doesn\*(Aqt exist \& # Thus we put an eval around it. \& eval { $dbh\->do("DROP TABLE foo") }; \& print "Dropping foo failed: $@\en" if $@; \& \& # Create a new table \*(Aqfoo\*(Aq. This must not fail, thus we don\*(Aqt \& # catch errors. \& $dbh\->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))"); \& \& # INSERT some data into \*(Aqfoo\*(Aq. We are using $dbh\->quote() for \& # quoting the name. \& $dbh\->do("INSERT INTO foo VALUES (1, " . $dbh\->quote("Tim") . ")"); \& \& # same thing, but using placeholders (recommended!) \& $dbh\->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen"); \& \& # now retrieve data from the table. \& my $sth = $dbh\->prepare("SELECT * FROM foo"); \& $sth\->execute(); \& while (my $ref = $sth\->fetchrow_hashref()) { \& print "Found a row: id = $ref\->{\*(Aqid\*(Aq}, name = $ref\->{\*(Aqname\*(Aq}\en"; \& } \& $sth\->finish(); \& \& # Disconnect from the database. \& $dbh\->disconnect(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBDBD::mysql\fR 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 \s-1API\s0 that comes with the MySQL relational database management system. Most functions provided by this programming \s-1API\s0 are supported. Some rarely used functions are missing, mainly because no-one ever requested them. :\-) .PP In what follows we first discuss the use of DBD::mysql, because this is what you will need the most. For installation, see the separate document DBD::mysql::INSTALL. See \*(L"\s-1EXAMPLE\s0\*(R" for a simple example above. .PP From perl you activate the interface with the statement .PP .Vb 1 \& use DBI; .Ve .PP 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 method like so: .PP .Vb 2 \& $dbh = DBI\->connect("DBI:mysql:database=$db;host=$host", \& $user, $password, {RaiseError => 1}); .Ve .PP Once you have connected to a database, you can execute \s-1SQL\s0 statements with: .PP .Vb 3 \& my $query = sprintf("INSERT INTO foo VALUES (%d, %s)", \& $number, $dbh\->quote("name")); \& $dbh\->do($query); .Ve .PP See \s-1DBI\s0 for details on the quote and do methods. An alternative approach is .PP .Vb 2 \& $dbh\->do("INSERT INTO foo VALUES (?, ?)", undef, \& $number, $name); .Ve .PP in which case the quote method is executed automatically. See also the bind_param method in \s-1DBI\s0. See \*(L"\s-1DATABASE\s0 \s-1HANDLES\s0\*(R" below for more details on database handles. .PP If you want to retrieve results, you need to create a so-called statement handle with: .PP .Vb 2 \& $sth = $dbh\->prepare("SELECT * FROM $table"); \& $sth\->execute(); .Ve .PP This statement handle can be used for multiple things. First of all you can retrieve a row of data: .PP .Vb 1 \& my $row = $sth\->fetchrow_hashref(); .Ve .PP If your table has columns \s-1ID\s0 and \s-1NAME\s0, then \f(CW$row\fR will be hash ref with keys \s-1ID\s0 and \s-1NAME\s0. See \*(L"\s-1STATEMENT\s0 \s-1HANDLES\s0\*(R" below for more details on statement handles. .PP But now for a more formal approach: .SS "Class Methods" .IX Subsection "Class Methods" .IP "\fBconnect\fR" 4 .IX Item "connect" .Vb 1 \& use DBI; \& \& $dsn = "DBI:mysql:$database"; \& $dsn = "DBI:mysql:database=$database;host=$hostname"; \& $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; \& \& $dbh = DBI\->connect($dsn, $user, $password); .Ve .Sp A \f(CW\*(C`database\*(C'\fR must always be specified. .RS 4 .IP "host" 4 .IX Item "host" .PD 0 .IP "port" 4 .IX Item "port" .PD The hostname, if not specified or specified as '' or 'localhost', will default to a MySQL server running on the local machine using the default for the \s-1UNIX\s0 socket. To connect to a MySQL server on the local machine via \s-1TCP\s0, you must specify the loopback \s-1IP\s0 address (127.0.0.1) as the host. .Sp Should the MySQL server be running on a non-standard port number, you may explicitly state the port number to connect to in the \f(CW\*(C`hostname\*(C'\fR argument, by concatenating the \fIhostname\fR and \fIport number\fR together separated by a colon ( \f(CW\*(C`:\*(C'\fR ) character or by using the \f(CW\*(C`port\*(C'\fR argument. .Sp To connect to a MySQL server on localhost using \s-1TCP/IP\s0, you must specify the hostname as 127.0.0.1 (with the optional port). .IP "mysql_client_found_rows" 4 .IX Item "mysql_client_found_rows" Enables (\s-1TRUE\s0 value) or disables (\s-1FALSE\s0 value) the flag \s-1CLIENT_FOUND_ROWS\s0 while connecting to the MySQL server. This has a somewhat funny effect: Without mysql_client_found_rows, if you perform a query like .Sp .Vb 1 \& UPDATE $table SET id = 1 WHERE id = 1; .Ve .Sp then the MySQL engine will always return 0, because no rows have changed. With mysql_client_found_rows however, it will return the number of rows that have an id 1, as some people are expecting. (At least for compatibility to other engines.) .IP "mysql_compression" 4 .IX Item "mysql_compression" If your \s-1DSN\s0 contains the option \*(L"mysql_compression=1\*(R", then the communication between client and server will be compressed. .IP "mysql_connect_timeout" 4 .IX Item "mysql_connect_timeout" If your \s-1DSN\s0 contains the option \*(L"mysql_connect_timeout=##\*(R", the connect request to the server will timeout if it has not been successful after the given number of seconds. .IP "mysql_write_timeout" 4 .IX Item "mysql_write_timeout" If your \s-1DSN\s0 contains the option \*(L"mysql_write_timeout=##\*(R", the write operation to the server will timeout if it has not been successful after the given number of seconds. .IP "mysql_read_timeout" 4 .IX Item "mysql_read_timeout" If your \s-1DSN\s0 contains the option \*(L"mysql_read_timeout=##\*(R", the read operation to the server will timeout if it has not been successful after the given number of seconds. .IP "mysql_init_command" 4 .IX Item "mysql_init_command" If your \s-1DSN\s0 contains the option \*(L"mysql_init_command=##\*(R", then this \s-1SQL\s0 statement is executed when connecting to the MySQL server. It is automatically re-executed if reconnection occurs. .IP "mysql_skip_secure_auth" 4 .IX Item "mysql_skip_secure_auth" This option is for older mysql databases that don't have secure auth set. .IP "mysql_read_default_file" 4 .IX Item "mysql_read_default_file" .PD 0 .IP "mysql_read_default_group" 4 .IX Item "mysql_read_default_group" .PD These options can be used to read a config file like /etc/my.cnf or ~/.my.cnf. By default MySQL's C client library doesn't use any config files unlike the client programs (mysql, mysqladmin, ...) that do, but outside of the C client library. Thus you need to explicitly request reading a config file, as in .Sp .Vb 2 \& $dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf"; \& $dbh = DBI\->connect($dsn, $user, $password) .Ve .Sp The option mysql_read_default_group can be used to specify the default group in the config file: Usually this is the \fIclient\fR group, but see the following example: .Sp .Vb 2 \& [client] \& host=localhost \& \& [perl] \& host=perlhost .Ve .Sp (Note the order of the entries! The example won't work, if you reverse the [client] and [perl] sections!) .Sp If you read this config file, then you'll be typically connected to \&\fIlocalhost\fR. However, by using .Sp .Vb 3 \& $dsn = "DBI:mysql:test;mysql_read_default_group=perl;" \& . "mysql_read_default_file=/home/joe/my.cnf"; \& $dbh = DBI\->connect($dsn, $user, $password); .Ve .Sp you'll be connected to \fIperlhost\fR. Note that if you specify a default group and do not specify a file, then the default config files will all be read. See the documentation of the C function \fImysql_options()\fR for details. .IP "mysql_socket" 4 .IX Item "mysql_socket" It is possible to choose the Unix socket that is used for connecting to the server. This is done, for example, with .Sp .Vb 1 \& mysql_socket=/dev/mysql .Ve .Sp Usually there's no need for this option, unless you are using another location for the socket than that built into the client. .IP "mysql_ssl" 4 .IX Item "mysql_ssl" A true value turns on the \s-1CLIENT_SSL\s0 flag when connecting to the MySQL database: .Sp .Vb 1 \& mysql_ssl=1 .Ve .Sp This means that your communication with the server will be encrypted. .Sp If you turn mysql_ssl on, you might also wish to use the following flags: .IP "mysql_ssl_client_key" 4 .IX Item "mysql_ssl_client_key" .PD 0 .IP "mysql_ssl_client_cert" 4 .IX Item "mysql_ssl_client_cert" .IP "mysql_ssl_ca_file" 4 .IX Item "mysql_ssl_ca_file" .IP "mysql_ssl_ca_path" 4 .IX Item "mysql_ssl_ca_path" .IP "mysql_ssl_cipher" 4 .IX Item "mysql_ssl_cipher" .PD These are used to specify the respective parameters of a call to mysql_ssl_set, if mysql_ssl is turned on. .IP "mysql_local_infile" 4 .IX Item "mysql_local_infile" The \s-1LOCAL\s0 capability for \s-1LOAD\s0 \s-1DATA\s0 may be disabled in the MySQL client library by default. If your \s-1DSN\s0 contains the option \&\*(L"mysql_local_infile=1\*(R", \s-1LOAD\s0 \s-1DATA\s0 \s-1LOCAL\s0 will be enabled. (However, this option is *ineffective* if the server has also been configured to disallow \s-1LOCAL\s0.) .IP "mysql_multi_statements" 4 .IX Item "mysql_multi_statements" Support for multiple statements separated by a semicolon (;) may be enabled by using this option. Enabling this option may cause problems if server-side prepared statements are also enabled. .IP "Prepared statement support (server side prepare)" 4 .IX Item "Prepared statement support (server side prepare)" As of 3.0002_1, server side prepare statements were on by default (if your server was >= 4.1.3). As of 3.0009, they were off by default again due to issues with the prepared statement \s-1API\s0 (all other mysql connectors are set this way until C \s-1API\s0 issues are resolved). The requirement to use prepared statements still remains that you have a server >= 4.1.3 .Sp To use server side prepared statements, all you need to do is set the variable mysql_server_prepare in the connect: .Sp \&\f(CW$dbh\fR = \s-1DBI\-\s0>connect( \*(L"DBI:mysql:database=test;host=localhost;mysql_server_prepare=1\*(R", "\*(L", \*(R"", { RaiseError => 1, AutoCommit => 1 } ); .Sp * Note: delimiter for this param is ';' .Sp There are many benefits to using server side prepare statements, mostly if you are performing many inserts because of that fact that a single statement is prepared to accept multiple insert values. .Sp To make sure that the 'make test' step tests whether server prepare works, you just need to export the env variable \s-1MYSQL_SERVER_PREPARE:\s0 .Sp export MYSQL_SERVER_PREPARE=1 .IP "mysql_embedded_options" 4 .IX Item "mysql_embedded_options" The option can be used to pass 'command\-line' options to embedded server. .Sp Example: .Sp use \s-1DBI\s0; \&\f(CW$testdsn\fR=\*(L"DBI:mysqlEmb:database=test;mysql_embedded_options=\-\-help,\-\-verbose\*(R"; \&\f(CW$dbh\fR = \s-1DBI\-\s0>connect($testdsn,\*(L"a\*(R",\*(L"b\*(R"); .Sp This would cause the command line help to the embedded MySQL server library to be printed. .IP "mysql_embedded_groups" 4 .IX Item "mysql_embedded_groups" The option can be used to specify the groups in the config file(\fImy.cnf\fR) which will be used to get options for embedded server. If not specified [server] and [embedded] groups will be used. .Sp Example: .Sp \&\f(CW$testdsn\fR=\*(L"DBI:mysqlEmb:database=test;mysql_embedded_groups=embedded_server,common\*(R"; .IP "mysql_conn_attrs" 4 .IX Item "mysql_conn_attrs" The option is a hash of attribute names and values which can be used to send custom connection attributes to the server. .Sp .Vb 2 \& node1$ cat ./foo.pl \& #!/usr/bin/perl \& \& use DBI; \& use Data::Dumper; \& \& my ($test_dsn, $test_user, $test_password) = ($ARGV[0], $ARGV[1], $ARGV[2]); \& \& my $dbh= DBI\->connect($test_dsn, $test_user, $test_password, \& { AutoCommit => 0, \& mysql_conn_attrs => { foo => \*(Aqbar\*(Aq, wiz => \*(Aqbang\*(Aq }, \& }); \& \& my $results = $dbh\->selectall_hashref(\*(AqSELECT * FROM performance_schema.session_connect_attrs\*(Aq, \*(AqATTR_NAME\*(Aq); \& print Dumper($results); \& \& $dbh\->disconnect(); \& node1$ perl ./foo.pl \*(AqDBI:mysql:test;hostname=127.0.0.1;port=5624\*(Aq msandbox msandbox \& $VAR1 = { \& \*(Aqprogram_name\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aq./foo.pl\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aqprogram_name\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq5\*(Aq \& }, \& \*(Aq_os\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aqosx10.8\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aq_os\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq0\*(Aq \& }, \& \*(Aqwiz\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aqbang\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aqwiz\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq3\*(Aq \& }, \& \*(Aq_platform\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aqx86_64\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aq_platform\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq4\*(Aq \& }, \& \*(Aq_client_name\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aqlibmysql\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aq_client_name\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq1\*(Aq \& }, \& \*(Aq_pid\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aq59860\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aq_pid\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq2\*(Aq \& }, \& \*(Aqfoo\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aqbar\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aqfoo\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq6\*(Aq \& }, \& \*(Aq_client_version\*(Aq => { \& \*(AqATTR_VALUE\*(Aq => \*(Aq5.6.24\*(Aq, \& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq, \& \*(AqATTR_NAME\*(Aq => \*(Aq_client_version\*(Aq, \& \*(AqORDINAL_POSITION\*(Aq => \*(Aq7\*(Aq \& } \& }; .Ve .RE .RS 4 .RE .SS "Private MetaData Methods" .IX Subsection "Private MetaData Methods" .IP "\fBListDBs\fR" 4 .IX Item "ListDBs" .Vb 4 \& my $drh = DBI\->install_driver("mysql"); \& @dbs = $drh\->func("$hostname:$port", \*(Aq_ListDBs\*(Aq); \& @dbs = $drh\->func($hostname, $port, \*(Aq_ListDBs\*(Aq); \& @dbs = $dbh\->func(\*(Aq_ListDBs\*(Aq); .Ve .Sp Returns a list of all databases managed by the MySQL server running on \f(CW$hostname\fR, port \f(CW$port\fR. This is a legacy method. Instead, you should use the portable method .Sp .Vb 1 \& @dbs = DBI\->data_sources("mysql"); .Ve .SS "Server Administration" .IX Subsection "Server Administration" .IP "admin" 4 .IX Item "admin" .Vb 4 \& $rc = $drh\->func("createdb", $dbname, [host, user, password,], \*(Aqadmin\*(Aq); \& $rc = $drh\->func("dropdb", $dbname, [host, user, password,], \*(Aqadmin\*(Aq); \& $rc = $drh\->func("shutdown", [host, user, password,], \*(Aqadmin\*(Aq); \& $rc = $drh\->func("reload", [host, user, password,], \*(Aqadmin\*(Aq); \& \& or \& \& $rc = $dbh\->func("createdb", $dbname, \*(Aqadmin\*(Aq); \& $rc = $dbh\->func("dropdb", $dbname, \*(Aqadmin\*(Aq); \& $rc = $dbh\->func("shutdown", \*(Aqadmin\*(Aq); \& $rc = $dbh\->func("reload", \*(Aqadmin\*(Aq); .Ve .Sp For server administration you need a server connection. For obtaining this connection you have two options: Either use a driver handle (drh) and supply the appropriate arguments (host, defaults localhost, user, defaults to '' and password, defaults to ''). A driver handle can be obtained with .Sp .Vb 1 \& $drh = DBI\->install_driver(\*(Aqmysql\*(Aq); .Ve .Sp Otherwise reuse the existing connection of a database handle (dbh). .Sp There's only one function available for administrative purposes, comparable to the mysqladmin programs. The command being execute depends on the first argument: .RS 4 .IP "createdb" 4 .IX Item "createdb" Creates the database \f(CW$dbname\fR. Equivalent to \*(L"mysqladmin create \f(CW$dbname\fR\*(R". .IP "dropdb" 4 .IX Item "dropdb" Drops the database \f(CW$dbname\fR. Equivalent to \*(L"mysqladmin drop \f(CW$dbname\fR\*(R". .Sp It should be noted that database deletion is \&\fInot prompted for\fR in any way. Nor is it undo-able from \s-1DBI\s0. .Sp .Vb 1 \& Once you issue the dropDB() method, the database will be gone! .Ve .Sp These method should be used at your own risk. .IP "shutdown" 4 .IX Item "shutdown" Silently shuts down the database engine. (Without prompting!) Equivalent to \*(L"mysqladmin shutdown\*(R". .IP "reload" 4 .IX Item "reload" Reloads the servers configuration files and/or tables. This can be particularly important if you modify access privileges or create new users. .RE .RS 4 .RE .SH "DATABASE HANDLES" .IX Header "DATABASE HANDLES" The DBD::mysql driver supports the following attributes of database handles (read only): .PP .Vb 9 \& $errno = $dbh\->{\*(Aqmysql_errno\*(Aq}; \& $error = $dbh\->{\*(Aqmysql_error\*(Aq}; \& $info = $dbh\->{\*(Aqmysql_hostinfo\*(Aq}; \& $info = $dbh\->{\*(Aqmysql_info\*(Aq}; \& $insertid = $dbh\->{\*(Aqmysql_insertid\*(Aq}; \& $info = $dbh\->{\*(Aqmysql_protoinfo\*(Aq}; \& $info = $dbh\->{\*(Aqmysql_serverinfo\*(Aq}; \& $info = $dbh\->{\*(Aqmysql_stat\*(Aq}; \& $threadId = $dbh\->{\*(Aqmysql_thread_id\*(Aq}; .Ve .PP These correspond to \fImysql_errno()\fR, \fImysql_error()\fR, \fImysql_get_host_info()\fR, \&\fImysql_info()\fR, \fImysql_insert_id()\fR, \fImysql_get_proto_info()\fR, \&\fImysql_get_server_info()\fR, \fImysql_stat()\fR and \fImysql_thread_id()\fR, respectively. .IP "mysql_clientinfo" 2 .IX Item "mysql_clientinfo" List information of the MySQL client library that DBD::mysql was built against: .Sp .Vb 1 \& print "$dbh\->{mysql_clientinfo}\en"; \& \& 5.2.0\-MariaDB .Ve .IP "mysql_clientversion" 2 .IX Item "mysql_clientversion" .Vb 1 \& print "$dbh\->{mysql_clientversion}\en"; \& \& 50200 .Ve .IP "mysql_serverversion" 2 .IX Item "mysql_serverversion" .Vb 1 \& print "$dbh\->{mysql_serverversion}\en"; \& \& 50200 .Ve .IP "mysql_dbd_stats" 2 .IX Item "mysql_dbd_stats" .Vb 1 \& $info_hashref = $dhb\->{mysql_dbd_stats}; .Ve .Sp DBD::mysql keeps track of some statistics in the mysql_dbd_stats attribute. The following stats are being maintained: .RS 2 .IP "auto_reconnects_ok" 8 .IX Item "auto_reconnects_ok" The number of times that DBD::mysql successfully reconnected to the mysql server. .IP "auto_reconnects_failed" 8 .IX Item "auto_reconnects_failed" The number of times that DBD::mysql tried to reconnect to mysql but failed. .RE .RS 2 .RE .PP The DBD::mysql driver also supports the following attributes of database handles (read/write): .IP "mysql_auto_reconnect" 4 .IX Item "mysql_auto_reconnect" This attribute determines whether DBD::mysql will automatically reconnect to mysql if the connection be lost. This feature defaults to off; however, if either the \s-1GATEWAY_INTERFACE\s0 or \s-1MOD_PERL\s0 environment variable is set, DBD::mysql will turn mysql_auto_reconnect on. Setting mysql_auto_reconnect to on is not advised if 'lock tables' is used because if DBD::mysql reconnect to mysql all table locks will be lost. This attribute is ignored when AutoCommit is turned off, and when AutoCommit is turned off, DBD::mysql will not automatically reconnect to the server. .Sp It is also possible to set the default value of the \f(CW\*(C`mysql_auto_reconnect\*(C'\fR attribute for the \f(CW$dbh\fR by passing it in the \f(CW\*(C`\e%attr\*(C'\fR hash for \f(CW\*(C`DBI\-\*(C'\fRconnect>. .Sp .Vb 1 \& $dbh\->{mysql_auto_reconnect} = 1; .Ve .Sp or .Sp .Vb 3 \& my $dbh = DBI\->connect($dsn, $user, $password, { \& mysql_auto_reconnect => 1, \& }); .Ve .Sp Note that if you are using a module or framework that performs reconnections for you (for example DBIx::Connector in fixup mode), this value must be set to 0. .IP "mysql_use_result" 4 .IX Item "mysql_use_result" This attribute forces the driver to use mysql_use_result rather than mysql_store_result. The former is faster and less memory consuming, but tends to block other processes. mysql_store_result is the default due to that fact storing the result is expected behavior with most applications. .Sp It is possible to set the default value of the \f(CW\*(C`mysql_use_result\*(C'\fR attribute for the \f(CW$dbh\fR via the \s-1DSN:\s0 .Sp .Vb 1 \& $dbh = DBI\->connect("DBI:mysql:test;mysql_use_result=1", "root", ""); .Ve .Sp You can also set it after creation of the database handle: .Sp .Vb 2 \& $dbh\->{mysql_use_result} = 0; # disable \& $dbh\->{mysql_use_result} = 1; # enable .Ve .Sp You can also set or unset the \f(CW\*(C`mysql_use_result\*(C'\fR setting on your statement handle, when creating the statement handle or after it has been created. See \*(L"\s-1STATEMENT\s0 \s-1HANDLES\s0\*(R". .IP "mysql_enable_utf8" 4 .IX Item "mysql_enable_utf8" This attribute determines whether DBD::mysql should assume strings stored in the database are utf8. This feature defaults to off. .Sp When set, a data retrieved from a textual column type (char, varchar, etc) will have the \s-1UTF\-8\s0 flag turned on if necessary. This enables character semantics on that string. You will also need to ensure that your database / table / column is configured to use \s-1UTF8\s0. See Chapter 10 of the mysql manual for details. .Sp Additionally, turning on this flag tells MySQL that incoming data should be treated as \s-1UTF\-8\s0. This will only take effect if used as part of the call to \fIconnect()\fR. If you turn the flag on after connecting, you will need to issue the command \f(CW\*(C`SET NAMES utf8\*(C'\fR to get the same effect. .Sp This option is experimental and may change in future versions. .IP "mysql_enable_utf8mb4" 4 .IX Item "mysql_enable_utf8mb4" This is similar to mysql_enable_utf8, but is capable of handling 4\-byte \&\s-1UTF\-8\s0 characters. .IP "mysql_bind_type_guessing" 4 .IX Item "mysql_bind_type_guessing" This attribute causes the driver (emulated prepare statements) to attempt to guess if a value being bound is a numeric value, and if so, doesn't quote the value. This was created by Dragonchild and is one way to deal with the performance issue of using quotes in a statement that is inserting or updating a large numeric value. This was previously called \&\f(CW\*(C`unsafe_bind_type_guessing\*(C'\fR because it is experimental. I have successfully run the full test suite with this option turned on, the name can now be simply \f(CW\*(C`mysql_bind_type_guessing\*(C'\fR. .Sp \&\s-1CAVEAT:\s0 Even though you can insert an integer value into a character column, if this column is indexed, if you query that column with the integer value not being quoted, it will not use the index: .Sp .Vb 10 \& MariaDB [test]> explain select * from test where value0 = \*(Aq3\*(Aq \eG \& *************************** 1. row *************************** \& id: 1 \& select_type: SIMPLE \& table: test \& type: ref \& possible_keys: value0 \& key: value0 \& key_len: 13 \& ref: const \& rows: 1 \& Extra: Using index condition \& 1 row in set (0.00 sec) \& \& MariaDB [test]> explain select * from test where value0 = 3 \& \-> \eG \& *************************** 1. row *************************** \& id: 1 \& select_type: SIMPLE \& table: test \& type: ALL \& possible_keys: value0 \& key: NULL \& key_len: NULL \& ref: NULL \& rows: 6 \& Extra: Using where \& 1 row in set (0.00 sec) .Ve .Sp See bug: https://rt.cpan.org/Ticket/Display.html?id=43822 .Sp \&\f(CW\*(C`mysql_bind_type_guessing\*(C'\fR can be turned on via .Sp .Vb 1 \& \- through DSN \& \& my $dbh= DBI\->connect(\*(AqDBI:mysql:test\*(Aq, \*(Aqusername\*(Aq, \*(Aqpass\*(Aq, \& { mysql_bind_type_guessing => 1}) \& \& \- OR after handle creation \& \& $dbh\->{mysql_bind_type_guessing} = 1; .Ve .IP "mysql_bind_comment_placeholders" 4 .IX Item "mysql_bind_comment_placeholders" This attribute causes the driver (emulated prepare statements) will cause any placeholders in comments to be bound. This is not correct prepared statement behavior, but some developers have come to depend on this behavior, so I have made it available in 4.015 .IP "mysql_no_autocommit_cmd" 4 .IX Item "mysql_no_autocommit_cmd" This attribute causes the driver to not issue 'set autocommit' either through explicit or using \fImysql_autocommit()\fR. This is particularly useful in the case of using MySQL Proxy. .Sp See the bug report: .Sp https://rt.cpan.org/Public/Bug/Display.html?id=46308 .Sp \&\f(CW\*(C`mysql_no_autocommit_cmd\*(C'\fR can be turned on when creating the database handle: .Sp .Vb 2 \& my $dbh = DBI\->connect(\*(AqDBI:mysql:test\*(Aq, \*(Aqusername\*(Aq, \*(Aqpass\*(Aq, \& { mysql_no_autocommit_cmd => 1}); .Ve .Sp or using an existing database handle: .Sp .Vb 1 \& $dbh\->{mysql_no_autocommit_cmd} = 1; .Ve .SH "STATEMENT HANDLES" .IX Header "STATEMENT HANDLES" The statement handles of DBD::mysql support a number of attributes. You access these by using, for example, .PP .Vb 1 \& my $numFields = $sth\->{NUM_OF_FIELDS}; .Ve .PP Note, that most attributes are valid only after a successful \fIexecute\fR. An \f(CW\*(C`undef\*(C'\fR value will returned otherwise. The most important exception is the \f(CW\*(C`mysql_use_result\*(C'\fR attribute, which forces the driver to use mysql_use_result rather than mysql_store_result. The former is faster and less memory consuming, but tends to block other processes. (That's why mysql_store_result is the default.) .PP To set the \f(CW\*(C`mysql_use_result\*(C'\fR attribute, use either of the following: .PP .Vb 1 \& my $sth = $dbh\->prepare("QUERY", { mysql_use_result => 1}); .Ve .PP or .PP .Vb 2 \& my $sth = $dbh\->prepare($sql); \& $sth\->{mysql_use_result} = 1; .Ve .PP Column dependent attributes, for example \fI\s-1NAME\s0\fR, the column names, are returned as a reference to an array. The array indices are corresponding to the indices of the arrays returned by \fIfetchrow\fR and similar methods. For example the following code will print a header of table names together with all rows: .PP .Vb 2 \& my $sth = $dbh\->prepare("SELECT * FROM $table") || \& die "Error:" . $dbh\->errstr . "\en"; \& \& $sth\->execute || die "Error:" . $sth\->errstr . "\en"; \& \& my $names = $sth\->{NAME}; \& my $numFields = $sth\->{\*(AqNUM_OF_FIELDS\*(Aq} \- 1; \& for my $i ( 0..$numFields ) { \& printf("%s%s", $i ? "," : "", $$names[$i]); \& } \& print "\en"; \& while (my $ref = $sth\->fetchrow_arrayref) { \& for my $i ( 0..$numFields ) { \& printf("%s%s", $i ? "," : "", $$ref[$i]); \& } \& print "\en"; \& } .Ve .PP For portable applications you should restrict yourself to attributes with capitalized or mixed case names. Lower case attribute names are private to DBD::mysql. The attribute list includes: .IP "ChopBlanks" 4 .IX Item "ChopBlanks" this attribute determines whether a \fIfetchrow\fR will chop preceding and trailing blanks off the column values. Chopping blanks does not have impact on the \fImax_length\fR attribute. .IP "mysql_insertid" 4 .IX Item "mysql_insertid" MySQL has the ability to choose unique key values automatically. If this happened, the new \s-1ID\s0 will be stored in this attribute. An alternative way for accessing this attribute is via \f(CW$dbh\fR\->{'mysql_insertid'}. (Note we are using the \f(CW$dbh\fR in this case!) .IP "mysql_is_blob" 4 .IX Item "mysql_is_blob" Reference to an array of boolean values; \s-1TRUE\s0 indicates, that the respective column is a blob. This attribute is valid for MySQL only. .IP "mysql_is_key" 4 .IX Item "mysql_is_key" Reference to an array of boolean values; \s-1TRUE\s0 indicates, that the respective column is a key. This is valid for MySQL only. .IP "mysql_is_num" 4 .IX Item "mysql_is_num" Reference to an array of boolean values; \s-1TRUE\s0 indicates, that the respective column contains numeric values. .IP "mysql_is_pri_key" 4 .IX Item "mysql_is_pri_key" Reference to an array of boolean values; \s-1TRUE\s0 indicates, that the respective column is a primary key. .IP "mysql_is_auto_increment" 4 .IX Item "mysql_is_auto_increment" Reference to an array of boolean values; \s-1TRUE\s0 indicates that the respective column is an \s-1AUTO_INCREMENT\s0 column. This is only valid for MySQL. .IP "mysql_length" 4 .IX Item "mysql_length" .PD 0 .IP "mysql_max_length" 4 .IX Item "mysql_max_length" .PD A reference to an array of maximum column sizes. The \fImax_length\fR is the maximum physically present in the result table, \fIlength\fR gives the theoretically possible maximum. \fImax_length\fR is valid for MySQL only. .IP "\s-1NAME\s0" 4 .IX Item "NAME" A reference to an array of column names. .IP "\s-1NULLABLE\s0" 4 .IX Item "NULLABLE" A reference to an array of boolean values; \s-1TRUE\s0 indicates that this column may contain \s-1NULL\s0's. .IP "\s-1NUM_OF_FIELDS\s0" 4 .IX Item "NUM_OF_FIELDS" Number of fields returned by a \fI\s-1SELECT\s0\fR or \fI\s-1LISTFIELDS\s0\fR statement. You may use this for checking whether a statement returned a result: A zero value indicates a non-SELECT statement like \fI\s-1INSERT\s0\fR, \&\fI\s-1DELETE\s0\fR or \fI\s-1UPDATE\s0\fR. .IP "mysql_table" 4 .IX Item "mysql_table" A reference to an array of table names, useful in a \fI\s-1JOIN\s0\fR result. .IP "\s-1TYPE\s0" 4 .IX Item "TYPE" A reference to an array of column types. The engine's native column types are mapped to portable types like \s-1\fIDBI::SQL_INTEGER\s0()\fR or \&\s-1\fIDBI::SQL_VARCHAR\s0()\fR, as good as possible. Not all native types have a meaningful equivalent, for example DBD::mysql::FIELD_TYPE_INTERVAL is mapped to \s-1\fIDBI::SQL_VARCHAR\s0()\fR. If you need the native column types, use \fImysql_type\fR. See below. .IP "mysql_type" 4 .IX Item "mysql_type" A reference to an array of MySQL's native column types, for example \&\fIDBD::mysql::FIELD_TYPE_SHORT()\fR or \fIDBD::mysql::FIELD_TYPE_STRING()\fR. Use the \fI\s-1TYPE\s0\fR attribute, if you want portable types like \&\s-1\fIDBI::SQL_SMALLINT\s0()\fR or \s-1\fIDBI::SQL_VARCHAR\s0()\fR. .IP "mysql_type_name" 4 .IX Item "mysql_type_name" Similar to mysql, but type names and not numbers are returned. Whenever possible, the \s-1ANSI\s0 \s-1SQL\s0 name is preferred. .IP "mysql_warning_count" 4 .IX Item "mysql_warning_count" The number of warnings generated during execution of the \s-1SQL\s0 statement. This attribute is available on both statement handles and database handles. .SH "TRANSACTION SUPPORT" .IX Header "TRANSACTION SUPPORT" The transaction support works as follows: .IP "\(bu" 4 By default AutoCommit mode is on, following the \s-1DBI\s0 specifications. .IP "\(bu" 4 If you execute .Sp .Vb 1 \& $dbh\->{AutoCommit} = 0; .Ve .Sp or .Sp .Vb 1 \& $dbh\->{AutoCommit} = 1; .Ve .Sp then the driver will set the MySQL server variable autocommit to 0 or 1, respectively. Switching from 0 to 1 will also issue a \s-1COMMIT\s0, following the \s-1DBI\s0 specifications. .IP "\(bu" 4 The methods .Sp .Vb 2 \& $dbh\->rollback(); \& $dbh\->commit(); .Ve .Sp will issue the commands \s-1ROLLBACK\s0 and \s-1COMMIT\s0, respectively. A \&\s-1ROLLBACK\s0 will also be issued if AutoCommit mode is off and the database handles \s-1DESTROY\s0 method is called. Again, this is following the \s-1DBI\s0 specifications. .PP Given the above, you should note the following: .IP "\(bu" 4 You should never change the server variable autocommit manually, unless you are ignoring \s-1DBI\s0's transaction support. .IP "\(bu" 4 Switching AutoCommit mode from on to off or vice versa may fail. You should always check for errors when changing AutoCommit mode. The suggested way of doing so is using the \s-1DBI\s0 flag RaiseError. If you don't like RaiseError, you have to use code like the following: .Sp .Vb 4 \& $dbh\->{AutoCommit} = 0; \& if ($dbh\->{AutoCommit}) { \& # An error occurred! \& } .Ve .IP "\(bu" 4 If you detect an error while changing the AutoCommit mode, you should no longer use the database handle. In other words, you should disconnect and reconnect again, because the transaction mode is unpredictable. Alternatively you may verify the transaction mode by checking the value of the server variable autocommit. However, such behaviour isn't portable. .IP "\(bu" 4 DBD::mysql has a \*(L"reconnect\*(R" feature that handles the so-called MySQL \*(L"morning bug\*(R": If the server has disconnected, most probably due to a timeout, then by default the driver will reconnect and attempt to execute the same \s-1SQL\s0 statement again. However, this behaviour is disabled when AutoCommit is off: Otherwise the transaction state would be completely unpredictable after a reconnect. .IP "\(bu" 4 The \*(L"reconnect\*(R" feature of DBD::mysql can be toggled by using the mysql_auto_reconnect attribute. This behaviour should be turned off in code that uses \s-1LOCK\s0 \s-1TABLE\s0 because if the database server time out and DBD::mysql reconnect, table locks will be lost without any indication of such loss. .SH "MULTIPLE RESULT SETS" .IX Header "MULTIPLE RESULT SETS" DBD::mysql supports multiple result sets, thanks to Guy Harrison! .PP The basic usage of multiple result sets is .PP .Vb 7 \& do \& { \& while (@row = $sth\->fetchrow_array()) \& { \& do stuff; \& } \& } while ($sth\->more_results) .Ve .PP An example would be: .PP .Vb 1 \& $dbh\->do("drop procedure if exists someproc") or print $DBI::errstr; \& \& $dbh\->do("create procedure someproc() deterministic \& begin \& declare a,b,c,d int; \& set a=1; \& set b=2; \& set c=3; \& set d=4; \& select a, b, c, d; \& select d, c, b, a; \& select b, a, c, d; \& select c, b, d, a; \& end") or print $DBI::errstr; \& \& $sth=$dbh\->prepare(\*(Aqcall someproc()\*(Aq) || \& die $DBI::err.": ".$DBI::errstr; \& \& $sth\->execute || die DBI::err.": ".$DBI::errstr; $rowset=0; \& do { \& print "\enRowset ".++$i."\en\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en\en"; \& foreach $colno (0..$sth\->{NUM_OF_FIELDS}\-1) { \& print $sth\->{NAME}\->[$colno]."\et"; \& } \& print "\en"; \& while (@row= $sth\->fetchrow_array()) { \& foreach $field (0..$#row) { \& print $row[$field]."\et"; \& } \& print "\en"; \& } \& } until (!$sth\->more_results) .Ve .PP For more examples, please see the eg/ directory. This is where helpful DBD::mysql code snippets will be added in the future. .SS "Issues with multiple result sets" .IX Subsection "Issues with multiple result sets" Please be aware ther could be issues if your result sets are \*(L"jagged\*(R", meaning the number of columns of your results vary. Varying numbers of columns could result in your script crashing. .SH "MULTITHREADING" .IX Header "MULTITHREADING" The multithreading capabilities of DBD::mysql depend completely on the underlying C libraries. The modules are working with handle data only, no global variables are accessed or (to the best of my knowledge) thread unsafe functions are called. Thus DBD::mysql is believed to be completely thread safe, if the C libraries are thread safe and you don't share handles among threads. .PP The obvious question is: Are the C libraries thread safe? In the case of MySQL the answer is \*(L"mostly\*(R" and, in theory, you should be able to get a \*(L"yes\*(R", if the C library is compiled for being thread safe (By default it isn't.) by passing the option \-with\-thread\-safe\-client to configure. See the section on \fIHow to make a threadsafe client\fR in the manual. .SH "ASYNCHRONOUS QUERIES" .IX Header "ASYNCHRONOUS QUERIES" You can make a single asynchronous query per MySQL connection; this allows you to submit a long-running query to the server and have an event loop inform you when it's ready. An asynchronous query is started by either setting the 'async' attribute to a true value in the \*(L"do\*(R" in \s-1DBI\s0 method, or in the \*(L"prepare\*(R" in \s-1DBI\s0 method. Statements created with 'async' set to true in prepare always run their queries asynchronously when \*(L"execute\*(R" in \s-1DBI\s0 is called. The driver also offers three additional methods: \&\f(CW\*(C`mysql_async_result\*(C'\fR, \f(CW\*(C`mysql_async_ready\*(C'\fR, and \f(CW\*(C`mysql_fd\*(C'\fR. \&\f(CW\*(C`mysql_async_result\*(C'\fR returns what do or execute would have; that is, the number of rows affected. \f(CW\*(C`mysql_async_ready\*(C'\fR returns true if \&\f(CW\*(C`mysql_async_result\*(C'\fR will not block, and zero otherwise. They both return \&\f(CW\*(C`undef\*(C'\fR if that handle is not currently running an asynchronous query. \&\f(CW\*(C`mysql_fd\*(C'\fR returns the file descriptor number for the MySQL connection; you can use this in an event loop. .PP Here's an example of how to use the asynchronous query interface: .PP .Vb 7 \& use feature \*(Aqsay\*(Aq; \& $dbh\->do(\*(AqSELECT SLEEP(10)\*(Aq, { async => 1 }); \& until($dbh\->mysql_async_ready) { \& say \*(Aqnot ready yet!\*(Aq; \& sleep 1; \& } \& my $rows = $dbh\->mysql_async_result; .Ve .SH "INSTALLATION" .IX Header "INSTALLATION" See DBD::mysql::INSTALL. .SH "AUTHORS" .IX Header "AUTHORS" Originally, there was a non-DBI driver, Mysql, which was much like \&\s-1PHP\s0 drivers such as mysql and mysqli. The \fBMysql\fR module was originally written by Andreas Ko\*:nig who still, to this day, contributes patches to DBD::mysql. An emulated version of Mysql was provided to DBD::mysql from Jochen Wiedmann, but eventually deprecated as it was another bundle of code to maintain. .PP The first incarnation of DBD::mysql was developed by Alligator Descartes, who was also aided and abetted by Gary Shea, Andreas Ko\*:nig and Tim Bunce. .PP The current incarnation of \fBDBD::mysql\fR was written by Jochen Wiedmann, then numerous changes and bug-fixes were added by Rudy Lippan. Next, prepared statement support was added by Patrick Galbraith and Alexy Stroganov (who also solely added embedded server support). .PP For the past nine years DBD::mysql has been maintained by Patrick Galbraith (\fIpatg@patg.net\fR), and recently with the great help of Michiel Beijen (\fImichiel.beijen@gmail.com\fR), along with the entire community of Perl developers who keep sending patches to help continue improving DBD::mysql .SH "CONTRIBUTIONS" .IX Header "CONTRIBUTIONS" Anyone who desires to contribute to this project is encouraged to do so. Currently, the source code for this project can be found at Github: .PP https://github.com/perl5\-dbi/DBD\-mysql/ .PP Either fork this repository and produce a branch with your changeset that the maintainer can merge to his tree, or create a diff with git. The maintainer is more than glad to take contributions from the community as many features and fixes from DBD::mysql have come from the community. .SH "COPYRIGHT" .IX Header "COPYRIGHT" This module is .IP "\(bu" 4 Large Portions Copyright (c) 2004\-2013 Patrick Galbraith .IP "\(bu" 4 Large Portions Copyright (c) 2004\-2006 Alexey Stroganov .IP "\(bu" 4 Large Portions Copyright (c) 2003\-2005 Rudolf Lippan .IP "\(bu" 4 Large Portions Copyright (c) 1997\-2003 Jochen Wiedmann, with code portions .IP "\(bu" 4 Copyright (c)1994\-1997 their original authors .SH "LICENSE" .IX Header "LICENSE" This module is released under the same license as Perl itself. See for details. .SH "MAILING LIST SUPPORT" .IX Header "MAILING LIST SUPPORT" This module is maintained and supported on a mailing list, dbi-users. .PP To subscribe to this list, send an email to .PP dbi\-users\-subscribe@perl.org .PP Mailing list archives are at .PP .SH "ADDITIONAL DBI INFORMATION" .IX Header "ADDITIONAL DBI INFORMATION" Additional information on the \s-1DBI\s0 project can be found on the World Wide Web at the following \s-1URL:\s0 .PP .PP where documentation, pointers to the mailing lists and mailing list archives and pointers to the most current versions of the modules can be used. .PP Information on the \s-1DBI\s0 interface itself can be gained by typing: .PP .Vb 1 \& perldoc DBI .Ve .PP Information on DBD::mysql specifically can be gained by typing: .PP .Vb 1 \& perldoc DBD::mysql .Ve .PP (this will display the document you're currently reading) .SH "BUG REPORTING, ENHANCEMENT/FEATURE REQUESTS" .IX Header "BUG REPORTING, ENHANCEMENT/FEATURE REQUESTS" Please report bugs, including all the information needed such as DBD::mysql version, MySQL version, \s-1OS\s0 type/version, etc to this link: .PP https://rt.cpan.org/Dist/Display.html?Name=DBD\-mysql .PP Note: until recently, MySQL/Sun/Oracle responded to bugs and assisted in fixing bugs which many thanks should be given for their help! This driver is outside the realm of the numerous components they support, and the maintainer and community solely support DBD::mysql