.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" 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
..
.\}
.\" ========================================================================
.\"
.IX Title "DBD::mysql 3"
.TH DBD::mysql 3 "2019-01-09" "perl v5.10.1" "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;
\&
\& my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
\& my $dbh = DBI\->connect($dsn, $user, $password);
\&
\& my $sth = $dbh\->prepare(
\& \*(AqSELECT id, first_name, last_name FROM authors WHERE last_name = ?\*(Aq)
\& or die "prepare statement failed: $dbh\->errstr()";
\& $sth\->execute(\*(AqEggers\*(Aq) or die "execution failed: $dbh\->errstr()";
\& print $sth\->rows . " rows found.\en";
\& while (my $ref = $sth\->fetchrow_hashref()) {
\& print "Found a row: id = $ref\->{\*(Aqid\*(Aq}, fn = $ref\->{\*(Aqfirst_name\*(Aq}\en";
\& }
\& $sth\->finish;
.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
The \f(CW\*(C`database\*(C'\fR is not a required attribute, but please note that MySQL
has no such thing as a default database. If you don't specify the database
at connection time your active database will be null and you'd need to prefix
your tables with the database name; i.e. '\s-1SELECT\s0 * \s-1FROM\s0 mydb.mytable'.
.Sp
This is similar to the behavior of the mysql command line client. Also,
\&'\s-1SELECT\s0 \s-1\fIDATABASE\s0()\fR' will return the current database active for the handle.
.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).
.Sp
When connecting to a MySQL Server with IPv6, a bracketed IPv6 address should be used.
Example \s-1DSN:\s0
.Sp
.Vb 1
\& my $dsn = "DBI:mysql:;host=[1a12:2800:6f2:85::f20:8cf];port=3306";
.Ve
.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
server and enforce \s-1SSL\s0 encryption. A false value (which is default)
disable \s-1SSL\s0 encryption with the MySQL server.
.Sp
When enabling \s-1SSL\s0 encryption you should set also other \s-1SSL\s0 options,
at least mysql_ssl_ca_file or mysql_ssl_ca_path.
.Sp
.Vb 1
\& mysql_ssl=1 mysql_ssl_verify_server_cert=1 mysql_ssl_ca_file=/path/to/ca_cert.pem
.Ve
.Sp
This means that your communication with the server will be encrypted.
.Sp
Please note that this can only work if you enabled \s-1SSL\s0 when compiling
DBD::mysql; this is the default starting version 4.034.
See DBD::mysql::INSTALL for more details.
.IP "mysql_ssl_ca_file" 4
.IX Item "mysql_ssl_ca_file"
The path to a file in \s-1PEM\s0 format that contains a list of trusted \s-1SSL\s0
certificate authorities.
.Sp
When set MySQL server certificate is checked that it is signed by some
\&\s-1CA\s0 certificate in the list. Common Name value is not verified unless
\&\f(CW\*(C`mysql_ssl_verify_server_cert\*(C'\fR is enabled.
.IP "mysql_ssl_ca_path" 4
.IX Item "mysql_ssl_ca_path"
The path to a directory that contains trusted \s-1SSL\s0 certificate authority
certificates in \s-1PEM\s0 format.
.Sp
When set MySQL server certificate is checked that it is signed by some
\&\s-1CA\s0 certificate in the list. Common Name value is not verified unless
\&\f(CW\*(C`mysql_ssl_verify_server_cert\*(C'\fR is enabled.
.Sp
Please note that this option is supported only if your MySQL client was
compiled with OpenSSL library, and not with default yaSSL library.
.IP "mysql_ssl_verify_server_cert" 4
.IX Item "mysql_ssl_verify_server_cert"
Checks the server's Common Name value in the certificate that the server
sends to the client. The client verifies that name against the host name
the client uses for connecting to the server, and the connection fails if
there is a mismatch. For encrypted connections, this option helps prevent
man-in-the-middle attacks.
.Sp
Verification of the host name is disabled by default.
.IP "mysql_ssl_client_key" 4
.IX Item "mysql_ssl_client_key"
The name of the \s-1SSL\s0 key file in \s-1PEM\s0 format to use for establishing
a secure connection.
.IP "mysql_ssl_client_cert" 4
.IX Item "mysql_ssl_client_cert"
The name of the \s-1SSL\s0 certificate file in \s-1PEM\s0 format to use for
establishing a secure connection.
.IP "mysql_ssl_cipher" 4
.IX Item "mysql_ssl_cipher"
A list of permissible ciphers to use for connection encryption. If no
cipher in the list is supported, encrypted connections will not work.
.Sp
.Vb 2
\& mysql_ssl_cipher=AES128\-SHA
\& mysql_ssl_cipher=DHE\-RSA\-AES256\-SHA:AES128\-SHA
.Ve
.IP "mysql_ssl_optional" 4
.IX Item "mysql_ssl_optional"
Setting \f(CW\*(C`mysql_ssl_optional\*(C'\fR to true disables strict \s-1SSL\s0 enforcement
and makes \s-1SSL\s0 connection optional. This option opens security hole
for man-in-the-middle attacks. Default value is false which means
that \f(CW\*(C`mysql_ssl\*(C'\fR set to true enforce \s-1SSL\s0 encryption.
.Sp
This option was introduced in 4.043 version of DBD::mysql. Due to
<The \s-1BACKRONYM\s0> and <The Riddle>
vulnerabilities in libmysqlclient library, enforcement of \s-1SSL\s0
encryption was not possbile and therefore \f(CW\*(C`mysql_ssl_optional=1\*(C'\fR
was effectively set for all DBD::mysql versions prior to 4.043.
Starting with 4.043, DBD::mysql with \f(CW\*(C`mysql_ssl=1\*(C'\fR could refuse
connection to MySQL server if underlaying libmysqlclient library is
vulnerable. Option \f(CW\*(C`mysql_ssl_optional\*(C'\fR can be used to make \s-1SSL\s0
connection vulnerable.
.IP "mysql_server_pubkey" 4
.IX Item "mysql_server_pubkey"
Path to the \s-1RSA\s0 public key of the server. This is used for the
sha256_password and caching_sha2_password authentication plugins.
.IP "mysql_get_server_pubkey" 4
.IX Item "mysql_get_server_pubkey"
Setting \f(CW\*(C`mysql_get_server_pubkey\*(C'\fR to true requests the public
\&\s-1RSA\s0 key of the server.
.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 "mysql_server_prepare" 4
.IX Item "mysql_server_prepare"
This option is used to enable server side prepared statements.
.Sp
To use server side prepared statements, all you need to do is set the variable
mysql_server_prepare in the connect:
.Sp
.Vb 6
\& $dbh = DBI\->connect(
\& "DBI:mysql:database=test;host=localhost;mysql_server_prepare=1",
\& "",
\& "",
\& { RaiseError => 1, AutoCommit => 1 }
\& );
.Ve
.Sp
or:
.Sp
.Vb 6
\& $dbh = DBI\->connect(
\& "DBI:mysql:database=test;host=localhost",
\& "",
\& "",
\& { RaiseError => 1, AutoCommit => 1, mysql_server_prepare => 1 }
\& );
.Ve
.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
.Vb 1
\& export MYSQL_SERVER_PREPARE=1
.Ve
.Sp
Please note that mysql server cannot prepare or execute some prepared statements.
In this case DBD::mysql fallbacks to normal non-prepared statement and tries again.
.IP "mysql_server_prepare_disable_fallback" 4
.IX Item "mysql_server_prepare_disable_fallback"
This option disable fallback to normal non-prepared statement when mysql server
does not support execution of current statement as prepared.
.Sp
Useful when you want to be sure that statement is going to be executed as
server side prepared. Error message and code in case of failure is propagated
back to \s-1DBI\s0.
.IP "mysql_embedded_options" 4
.IX Item "mysql_embedded_options"
The option <mysql_embedded_options> can be used to pass 'command\-line'
options to embedded server.
.Sp
Example:
.Sp
.Vb 3
\& use DBI;
\& $testdsn="DBI:mysqlEmb:database=test;mysql_embedded_options=\-\-help,\-\-verbose";
\& $dbh = DBI\->connect($testdsn,"a","b");
.Ve
.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 <mysql_embedded_groups> 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
.Vb 1
\& $testdsn="DBI:mysqlEmb:database=test;mysql_embedded_groups=embedded_server,common";
.Ve
.IP "mysql_conn_attrs" 4
.IX Item "mysql_conn_attrs"
The option <mysql_conn_attrs> is a hash of attribute names and values which can be
used to send custom connection attributes to the server. Some attributes like
\&'_os', '_platform', '_client_name' and '_client_version' are added by libmysqlclient
and 'program_name' is added by DBD::mysql.
.Sp
You can then later read these attributes from the performance schema tables which
can be quite helpful for profiling your database or creating statistics.
You'll have to use a MySQL 5.6 server and libmysqlclient or newer to leverage this
feature.
.Sp
.Vb 7
\& my $dbh= DBI\->connect($dsn, $user, $password,
\& { AutoCommit => 0,
\& mysql_conn_attrs => {
\& foo => \*(Aqbar\*(Aq,
\& wiz => \*(Aqbang\*(Aq
\& },
\& });
.Ve
.Sp
Now you can select the results from the performance schema tables. You can do this
in the same session, but also afterwards. It can be very useful to answer questions
like 'which script sent this query?'.
.Sp
.Vb 4
\& my $results = $dbh\->selectall_hashref(
\& \*(AqSELECT * FROM performance_schema.session_connect_attrs\*(Aq,
\& \*(AqATTR_NAME\*(Aq
\& );
.Ve
.Sp
This returns:
.Sp
.Vb 10
\& $result = {
\& \*(Aqfoo\*(Aq => {
\& \*(AqATTR_VALUE\*(Aq => \*(Aqbar\*(Aq,
\& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq,
\& \*(AqATTR_NAME\*(Aq => \*(Aqfoo\*(Aq,
\& \*(AqORDINAL_POSITION\*(Aq => \*(Aq6\*(Aq
\& },
\& \*(Aqwiz\*(Aq => {
\& \*(AqATTR_VALUE\*(Aq => \*(Aqbang\*(Aq,
\& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq,
\& \*(AqATTR_NAME\*(Aq => \*(Aqwiz\*(Aq,
\& \*(AqORDINAL_POSITION\*(Aq => \*(Aq3\*(Aq
\& },
\& \*(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_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_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
\& },
\& \*(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
\& },
\& \*(Aq_pid\*(Aq => {
\& \*(AqATTR_VALUE\*(Aq => \*(Aq59860\*(Aq,
\& \*(AqPROCESSLIST_ID\*(Aq => \*(Aq3\*(Aq,
\& \*(AqATTR_NAME\*(Aq => \*(Aq_pid\*(Aq,
\& \*(AqORDINAL_POSITION\*(Aq => \*(Aq2\*(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
\& }
\& };
.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
.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 = $dbh\->{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 for more
information the chapter on character set support in the MySQL manual:
<http://dev.mysql.com/doc/refman/5.7/en/charset.html>
.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.
.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
.IP "ping" 4
.IX Item "ping"
This can be used to send a ping to the server.
.Sp
.Vb 1
\& $rc = $dbh\->ping();
.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_gtids" 4
.IX Item "mysql_gtids"
Returns \s-1GTID\s0(s) if \s-1GTID\s0 session tracking is ensabled in the server via
session_track_gtids.
.IP "mysql_insertid" 4
.IX Item "mysql_insertid"
If the statement you executed performs an \s-1INSERT\s0, and there is an \s-1AUTO_INCREMENT\s0
column in the table you inserted in, this attribute holds the value stored into
the \s-1AUTO_INCREMENT\s0 column, if that value is automatically generated, by
storing \s-1NULL\s0 or 0 or was specified as an explicit value.
.Sp
Typically, you'd access the value via \f(CW$sth\fR\->{mysql_insertid}. The value can
also be accessed via \f(CW$dbh\fR\->{mysql_insertid} but this can easily
produce incorrect results in case one database handle is shared.
.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
.SS "Issues with multiple result sets"
.IX Subsection "Issues with multiple result sets"
Please be aware there 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 yes, since MySQL 5.5 it is.
.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 was not created with 'async' set to true
or if an asynchronous query was not started yet.
\&\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 König <koenig@kulturbox.de> 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 Kö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
<http://www.perl.com/perl/misc/Artistic.html> 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
<http://groups.google.com/group/perl.dbi.users?hl=en&lr=>
.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
<http://dbi.perl.org>
.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
Copyright 2K16 - 2K18 Indonesian Hacker Rulez