.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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 3pm" .TH DBD::mysql 3pm "2012-06-09" "perl v5.14.2" "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 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 \& $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 noone 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 sections on \s-1INSTALLATION\s0, and \*(L"\s-1WIN32\s0 \s-1INSTALLATION\s0\*(R" below. See \s-1EXAMPLE\s0 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 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-1\fIDBI\s0\fR\|(3) 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-1\fIDBI\s0\fR\|(3). 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 retreive 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" As of MySQL 3.22.3, a new feature is supported: 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_init_command" 4 .IX Item "mysql_init_command" .Vb 3 \& If your DSN contains the option "mysql_init_command_timeout=##", then \& this SQL statement is executed when connecting to the MySQL server. \& It is automatically re\-executed if reconnection occurs. .Ve .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" As of MySQL 3.21.15, 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" As of MySQL 3.23.49, 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" As of MySQL 4.1, 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"; .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 m(y)sqladmin 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"m(y)sqladmin create \f(CW$dbname\fR\*(R". .IP "dropdb" 4 .IX Item "dropdb" Drops the database \f(CW$dbname\fR. Equivalent to \*(L"m(y)sqladmin 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"m(y)sqladmin 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. .PP .Vb 1 \& $info_hashref = $dhb\->{mysql_dbd_stats} .Ve .PP DBD::mysql keeps track of some statistics in the mysql_dbd_stats attribute. The following stats are being maintained: .IP "auto_reconnects_ok" 4 .IX Item "auto_reconnects_ok" The number of times that DBD::mysql successfully reconnected to the mysql server. .IP "auto_reconnects_failed" 4 .IX Item "auto_reconnects_failed" The number of times that DBD::mysql tried to reconnect to mysql but failed. .PP The DBD::mysql driver also supports the following attribute(s) of database handles (read/write): .PP .Vb 2 \& $bool_value = $dbh\->{mysql_auto_reconnect}; \& $dbh\->{mysql_auto_reconnect} = $AutoReconnect ? 1 : 0; .Ve .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 envionment 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 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. (That's why mysql_store_result is the default.) .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 using several ways: .Sp .Vb 1 \& \- through DSN \& \& $dbh= DBI\->connect("DBI:mysql:test;mysql_use_result=1", "root", ""); \& \& \- after creation of database handle \& \& $dbh\->{\*(Aqmysql_use_result\*(Aq}=0; #disable \& $dbh\->{\*(Aqmysql_use_result\*(Aq}=1; #enable .Ve .Sp It is possible to set/unset the \f(CW\*(C`mysql_use_result\*(C'\fR attribute after creation of the statement handle. See below. .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_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 MariaDB [test]> explain select * from test where value0 = '3' \eG *************************** 1. row *************************** id: 1 select_type: \s-1SIMPLE\s0 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) .Sp MariaDB [test]> explain select * from test where value0 = 3 \-> \eG *************************** 1. row *************************** id: 1 select_type: \s-1SIMPLE\s0 table: test type: \s-1ALL\s0 possible_keys: value0 key: \s-1NULL\s0 key_len: \s-1NULL\s0 ref: \s-1NULL\s0 rows: 6 Extra: Using where 1 row in set (0.00 sec) .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 As well as: .Sp http://bugs.mysql.com/bug.php?id=32464 .Sp \&\f(CW\*(C`mysql_no_autocommit_cmd\*(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_no_autocommit_cmd => 1}) \& \& \- OR after handle creation \& \& $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\->{\*(AqNUM_OF_FIELDS\*(Aq}; .Ve .PP Note, that most attributes are valid only after a successfull \fIexecute\fR. An \f(CW\*(C`undef\*(C'\fR value will returned in that case. The most important exception is the \f(CW\*(C`mysql_use_result\*(C'\fR attribute: This 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("QUERY"); \& $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 10 \& my $sth = $dbh\->prepare("SELECT * FROM $table"); \& if (!$sth) { \& die "Error:" . $dbh\->errstr . "\en"; \& } \& if (!$sth\->execute) { \& die "Error:" . $sth\->errstr . "\en"; \& } \& my $names = $sth\->{\*(AqNAME\*(Aq}; \& my $numFields = $sth\->{\*(AqNUM_OF_FIELDS\*(Aq}; \& for (my $i = 0; $i < $numFields; $i++) { \& printf("%s%s", $i ? "," : "", $$names[$i]); \& } \& print "\en"; \& while (my $ref = $sth\->fetchrow_arrayref) { \& for (my $i = 0; $i < $numFields; $i++) { \& 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 "mysql_clientinfo" 4 .IX Item "mysql_clientinfo" List information of the MySQL client library that DBD::mysql was built against: .Sp print \*(L"$dbh\->{mysql_clientinfo}\en\*(R"; .Sp 5.2.0\-MariaDB .IP "mysql_clientversion" 4 .IX Item "mysql_clientversion" print \*(L"$dbh\->{mysql_clientversion}\en\*(R"; .Sp 50200 .IP "mysql_serverversion" 4 .IX Item "mysql_serverversion" print \*(L"$dbh\->{mysql_serverversion}\en\*(R"; .Sp 50200 .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 meaningfull 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. .SH "TRANSACTION SUPPORT" .IX Header "TRANSACTION SUPPORT" Beginning with DBD::mysql 2.0416, transactions are supported. 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\->{\*(AqAutoCommit\*(Aq} = 0; .Ve .Sp or .Sp .Vb 1 \& $dbh\->{\*(AqAutoCommit\*(Aq} = 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-1COMMIT\s0 and \s-1ROLLBACK\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\->{\*(AqAutoCommit\*(Aq} = 0; \& if ($dbh\->{\*(AqAutoCommit\*(Aq}) { \& # 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" As of version 3.0002_5, DBD::mysql supports multiple result sets (Thanks to Guy Harrison!). This is the first release of this functionality, so there may be issues. Please report bugs if you run into them! .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 somproc() 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}) { \& 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 snippits will be added in the future. .SS "Issues with Multiple result sets" .IX Subsection "Issues with Multiple result sets" So far, the main issue is 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. This is something that will be fixed soon. .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 truthy 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" Windows users may skip this section and pass over to \s-1WIN32\s0 \&\s-1INSTALLATION\s0 below. Others, go on reading. .SS "Environment Variables" .IX Subsection "Environment Variables" For ease of use, you can now set environment variables for DBD::mysql installation. You can set any or all of the options, and export them by putting them in your .bashrc or the like: .PP .Vb 12 \& export DBD_MYSQL_CFLAGS=\-I/usr/local/mysql/include/mysql \& export DBD_MYSQL_LIBS="\-L/usr/local/mysql/lib/mysql \-lmysqlclient" \& export DBD_MYSQL_EMBEDDED= \& export DBD_MYSQL_CONFIG=mysql_config \& export DBD_MYSQL_NOCATCHSTDERR=0 \& export DBD_MYSQL_NOFOUNDROWS=0 \& export DBD_MYSQL_SSL= \& export DBD_MYSQL_TESTDB=test \& export DBD_MYSQL_TESTHOST=localhost \& export DBD_MYSQL_TESTPASSWORD=s3kr1+ \& export DBD_MYSQL_TESTPORT=3306 \& export DBD_MYSQL_TESTUSER=me .Ve .PP The most useful may be the host, database, port, socket, user, and password. .PP Installation will first look to your mysql_config, and then your environment variables, and then it will guess with intelligent defaults. .SS "Installing with \s-1CPAN\s0" .IX Subsection "Installing with CPAN" First of all, you do not need an installed MySQL server for installing DBD::mysql. However, you need at least the client libraries and possibly the header files, if you are compiling DBD::mysql from source. In the case of MySQL you can create a client-only version by using the configure option \-\-without\-server. If you are using precompiled binaries, then it may be possible to use just selected \s-1RPM\s0's like MySQL-client and MySQL-devel or something similar, depending on the distribution. .PP First you need to install the \s-1DBI\s0 module. For using \fIdbimon\fR, a simple \s-1DBI\s0 shell it is recommended to install Data::ShowTable another Perl module. .PP I recommend trying automatic installation via the \s-1CPAN\s0 module. Try .PP .Vb 1 \& perl \-MCPAN \-e shell .Ve .PP If you are using the \s-1CPAN\s0 module for the first time, it will prompt you a lot of questions. If you finally receive the \s-1CPAN\s0 prompt, enter .PP .Vb 1 \& install Bundle::DBD::mysql .Ve .SS "Manual Installation" .IX Subsection "Manual Installation" If this fails (which may be the case for a number of reasons, for example because you are behind a firewall or don't have network access), you need to do a manual installation. First of all you need to fetch the modules from \s-1CPAN\s0 search .PP .Vb 1 \& http://search.cpan.org/ .Ve .PP The following modules are required .PP .Vb 3 \& DBI \& Data::ShowTable \& DBD::mysql .Ve .PP Then enter the following commands (note \- versions are just examples): .PP .Vb 6 \& gzip \-cd DBI\-(version).tar.gz | tar xf \- \& cd DBI\-(version) \& perl Makefile.PL \& make \& make test \& make install \& \& cd .. \& gzip \-cd Data\-ShowTable\-(version).tar.gz | tar xf \- \& cd Data\-ShowTable\-3.3 \& perl Makefile.PL \& make \& make install \& \& cd .. \& gzip \-cd DBD\-mysql\-(version)\-tar.gz | tar xf \- \& cd DBD\-mysql\-(version) \& perl Makefile.PL \& make \& make test \& make install .Ve .PP During \*(L"perl Makefile.PL\*(R" you will be prompted some questions. Other questions are the directories with header files and libraries. For example, of your file \fImysql.h\fR is in \fI/usr/include/mysql/mysql.h\fR, then enter the header directory \fI/usr\fR, likewise for \&\fI/usr/lib/mysql/libmysqlclient.a\fR or \fI/usr/lib/libmysqlclient.so\fR. .SH "WIN32 INSTALLATION" .IX Header "WIN32 INSTALLATION" If you are using ActivePerl, you may use ppm to install DBD-mysql. For Perl 5.6, upgrade to Build 623 or later, then it is sufficient to run .PP .Vb 2 \& ppm install DBI \& ppm install DBD::mysql .Ve .PP If you need an \s-1HTTP\s0 proxy, you might need to set the environment variable http_proxy, for example like this: .PP .Vb 1 \& set http_proxy=http://myproxy.com:8080/ .Ve .PP As of this writing, DBD::mysql is missing in the ActivePerl 5.8.0 repository. However, Randy Kobes has kindly donated an own distribution and the following might succeed: .PP .Vb 1 \& ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD\-mysql.ppd .Ve .PP Otherwise you definitely *need* a C compiler. And it *must* be the same compiler that was being used for compiling Perl itself. If you don't have a C compiler, the file \s-1README\s0.win32 from the Perl source distribution tells you where to obtain freely distributable C compilers like egcs or gcc. The Perl sources are available via \s-1CPAN\s0 search .PP .Vb 1 \& http://search.cpan.org .Ve .PP I recommend using the win32clients package for installing DBD::mysql under Win32, available for download on www.tcx.se. The following steps have been required for me: .IP "\-" 4 The current Perl versions (5.6, as of this writing) do have a problem with detecting the C libraries. I recommend to apply the following patch: .Sp .Vb 7 \& *** c:\ePerl\elib\eExtUtils\eLiblist.pm.orig Sat Apr 15 20:03:40 2000 \& \-\-\- c:\ePerl\elib\eExtUtils\eLiblist.pm Sat Apr 15 20:03:45 2000 \& *************** \& *** 230,235 **** \& \-\-\- 230,239 \-\-\-\- \& # add "$Config{installarchlib}/CORE" to default search path \& push @libpath, "$Config{installarchlib}/CORE"; \& \& + if ($VC and exists($ENV{LIB}) and defined($ENV{LIB})) { \& + push(@libpath, split(/;/, $ENV{LIB})); \& + } \& + \& foreach (Text::ParseWords::quotewords(\*(Aq\es+\*(Aq, 0, $potential_libs)){ \& \& $thislib = $_; .Ve .IP "\-" 4 Extract sources into \fIC:\e\fR. This will create a directory \fIC:\emysql\fR with subdirectories include and lib. .Sp \&\s-1IMPORTANT:\s0 Make sure this subdirectory is not shared by other \s-1TCX\s0 files! In particular do *not* store the MySQL server in the same directory. If the server is already installed in \fIC:\emysql\fR, choose a location like \fIC:\etmp\fR, extract the win32clients there. Note that you can remove this directory entirely once you have installed DBD::mysql. .IP "\-" 4 Extract the DBD::mysql sources into another directory, for example \fIC:\esrc\esiteperl\fR .IP "\-" 4 Open a \s-1DOS\s0 shell and change directory to \fIC:\esrc\esiteperl\fR. .IP "\-" 4 The next step is only required if you repeat building the modules: Make sure that you have a clean build tree by running .Sp .Vb 1 \& nmake realclean .Ve .Sp If you don't have \s-1VC++\s0, replace nmake with your flavour of make. If error messages are reported in this step, you may safely ignore them. .IP "\-" 4 Run .Sp .Vb 1 \& perl Makefile.PL .Ve .Sp which will prompt you for some settings. The really important ones are: .Sp .Vb 1 \& Which DBMS do you want to use? .Ve .Sp enter a 1 here (MySQL only), and .Sp .Vb 2 \& Where is your mysql installed? Please tell me the directory that \& contains the subdir include. .Ve .Sp where you have to enter the win32clients directory, for example \&\fIC:\emysql\fR or \fIC:\etmp\emysql\fR. .IP "\-" 4 Continued in the usual way: .Sp .Vb 2 \& nmake \& nmake install .Ve .PP If you want to create a \s-1PPM\s0 package for the ActiveState Perl version, then modify the above steps as follows: Run .PP .Vb 3 \& perl Makefile.PL NAME=DBD\-mysql BINARY_LOCATION=DBD\-mysql.tar.gz \& nmake ppd \& nmake .Ve .PP Once that is done, use tar and gzip (for example those from the CygWin32 distribution) to create an archive: .PP .Vb 3 \& mkdir x86 \& tar cf x86/DBD\-mysql.tar blib \& gzip x86/DBD\-mysql.tar .Ve .PP Put the files x86/DBD\-mysql.tar.gz and DBD\-mysql.ppd onto some \s-1WWW\s0 server and install them by typing .PP .Vb 1 \& install http://your.server.name/your/directory/DBD\-mysql.ppd .Ve .PP in the \s-1PPM\s0 program. .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 Ki\*:XXnig 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 Ki\*:XXnig 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 soley added embedded server support). .PP For the past seven years DBD::mysql has been maintained by Patrick Galbraith (\fIpatg@patg.net\fR) along with the entire community of Perl developers who keep sending patches and making Patrick's job easier. .SH "CONTRIBUTIONS" .IX Header "CONTRIBUTIONS" Anyone who desires to contribute to this project is encouraged to do so. Currently, the sourcecode for this project can be found at Github: .PP git://github.com/CaptTofu/DBD\-mysql.git .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 Large Portions Copyright (c) 2004\-2010 Patrick Galbraith Large Portions Copyright (c) 2004\-2006 Alexey Stroganov Large Portions Copyright (c) 2003\-2005 Rudolf Lippan Large Portions Copyright (c) 1997\-2003 Jochen Wiedmann, with code portions Copyright (c)1994\-1997 their original authors This module is released under the same license as Perl itself. See the Perl \s-1README\s0 for details. .SH "MAILING LIST SUPPORT" .IX Header "MAILING LIST SUPPORT" This module is maintained and supported on a mailing list, .PP .Vb 1 \& perl@lists.mysql.com .Ve .PP To subscribe to this list, go to .PP http://lists.mysql.com/perl?sub=1 .PP Mailing list archives are available at .PP http://lists.mysql.com/perl .PP Additionally you might try the dbi-user mailing list for questions about \&\s-1DBI\s0 and its modules in general. Subscribe via .PP dbi\-users\-subscribe@perl.org .PP Mailing list archives are at .PP http://groups.google.com/group/perl.dbi.users?hl=en&lr= .PP Also, the main \s-1DBI\s0 site is at .PP http://dbi.perl.org/ .PP And source: .PP git://github.com/CaptTofu/DBD\-mysql.git .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 .Vb 1 \& http://dbi.perl.org .Ve .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 right now! .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 http://bugs.mysql.com/