<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>MySQL Functions (PDO_MYSQL)</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-informix.connection.html">PDO_INFORMIX DSN</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a></div> <div class="up"><a href="pdo.drivers.html">PDO Drivers</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ref.pdo-mysql" class="reference"> <h1 class="title">MySQL Functions (PDO_MYSQL)</h1> <div class="partintro"> <div class="section" id="pdo-mysql.intro"> <h2 class="title">Introduction</h2> <p class="para"> PDO_MYSQL is a driver that implements the <a href="intro.pdo.html" class="link">PHP Data Objects (PDO) interface</a> to enable access from PHP to MySQL 3.x, 4.x and 5.x databases. </p> <p class="para"> PDO_MYSQL will take advantage of native prepared statement support present in MySQL 4.1 and higher. If you're using an older version of the mysql client libraries, PDO will emulate them for you. </p> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> Beware: Some MySQL table types (storage engines) do not support transactions. When writing transactional database code using a table type that does not support transactions, MySQL will pretend that a transaction was initiated successfully. In addition, any DDL queries issued will implicitly commit any pending transactions. </p> </div> </div> <div class="section" id="ref.pdo-mysql.installation"> <h2 class="title">Installation</h2> <p class="para"> Use <strong class="option configure">--with-pdo-mysql[=DIR]</strong> to install the PDO MySQL extension, where the optional <em>[=DIR]</em> is the MySQL base install directory. If <a href="book.mysqlnd.html" class="link">mysqlnd</a> is passed as <em>[=DIR]</em>, then the MySQL native driver will be used. </p> <p class="para"> Optionally, the <strong class="option configure">--with-mysql-sock[=DIR]</strong> sets to location to the MySQL unix socket pointer for all MySQL extensions, including PDO_MYSQL. If unspecified, the default locations are searched. </p> <p class="para"> Optionally, the <strong class="option configure">--with-zlib-dir[=DIR]</strong> is used to set the path to the libz install prefix. </p> <p class="para"> <div class="example-contents screen"> <div class="cdata"><pre> $ ./configure --with-pdo-mysql --with-mysql-sock=/var/mysql/mysql.sock </pre></div> </div> </p> <p class="para"> SSL support is enabled using the appropriate <a href="ref.pdo-mysql.html#pdo-mysql.constants" class="link">PDO_MySQL constants</a>, which is equivalent to calling the <a href="http://dev.mysql.com/doc/mysql/en/mysql-ssl-set.html" class="link external">» MySQL C API function mysql_ssl_set()</a>. Also, SSL cannot be enabled with <strong class="classname">PDO::setAttribute</strong> because the connection already exists. See also the MySQL documentation about <a href="http://dev.mysql.com/doc/mysql/en/configuring-for-ssl.html" class="link external">» connecting to MySQL with SSL</a>. </p> <table class="doctable table"> <caption><strong>Changelog</strong></caption> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.4.0</td> <td> MySQL client libraries 4.1 and below are no longer supported. </td> </tr> <tr> <td>5.3.9</td> <td> Added SSL support with mysqlnd and OpenSSL. </td> </tr> <tr> <td>5.3.7</td> <td> Added SSL support with libmysqlclient and OpenSSL. </td> </tr> </tbody> </table> </div> <div class="section" id="pdo-mysql.constants"> <h2 class="title">Predefined Constants</h2> <p class="simpara">The constants below are defined by this driver, and will only be available when the extension has been either compiled into PHP or dynamically loaded at runtime. In addition, these driver-specific constants should only be used if you are using this driver. Using driver-specific attributes with another driver may result in unexpected behaviour. <span class="function"><a href="pdo.getattribute.html" class="function">PDO::getAttribute()</a></span> may be used to obtain the <strong><code>PDO_ATTR_DRIVER_NAME</code></strong> attribute to check the driver, if your code can run against multiple drivers.</p> <dl> <dt id="pdo.constants.mysql-attr-use-buffered-query"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <span class="simpara"> If this attribute is set to <strong><code>TRUE</code></strong> on a <a href="class.pdostatement.html" class="classname">PDOStatement</a>, the MySQL driver will use the buffered versions of the MySQL API. If you're writing portable code, you should use <span class="function"><a href="pdostatement.fetchall.html" class="function">PDOStatement::fetchAll()</a></span> instead. </span> <p class="para"> <div class="example" id="example-977"><p><strong>Example #1 Forcing queries to be buffered in mysql</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_DRIVER_NAME</span><span style="color: #007700">) == </span><span style="color: #DD0000">'mysql'</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'select * from foo'</span><span style="color: #007700">,<br /> array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">MYSQL_ATTR_USE_BUFFERED_QUERY </span><span style="color: #007700">=> </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />} else {<br /> die(</span><span style="color: #DD0000">"my application only works with mysql; I should use \$stmt->fetchAll() instead"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-local-infile"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_LOCAL_INFILE</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Enable <em>LOAD LOCAL INFILE</em>. </p> <p class="para"> Note, this constant can only be used in the <em><code class="parameter">driver_options</code></em> array when constructing a new database handle. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-init-command"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_INIT_COMMAND</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting. </p> <p class="para"> Note, this constant can only be used in the <em><code class="parameter">driver_options</code></em> array when constructing a new database handle. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-read-default-file"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_READ_DEFAULT_FILE</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Read options from the named option file instead of from <var class="filename">my.cnf</var>. This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-read-default-group"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_READ_DEFAULT_GROUP</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Read options from the named group from <var class="filename">my.cnf</var> or the file specified with <strong><code>MYSQL_READ_DEFAULT_FILE</code></strong>. This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-max-buffer-size"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_MAX_BUFFER_SIZE</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Maximum buffer size. Defaults to 1 MiB. This constant is not supported when compiled against mysqlnd. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-direct-query"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_DIRECT_QUERY</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Perform direct queries, don't use prepared statements. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-found-rows"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_FOUND_ROWS</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Return the number of found (matched) rows, not the number of changed rows. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-ignore-space"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_IGNORE_SPACE</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Permit spaces after function names. Makes all functions names reserved words. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-compress"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_COMPRESS</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> Enable network communication compression. This is not supported when compiled against mysqlnd. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-ssl-ca"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_SSL_CA</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> The file path to the SSL certificate authority. </p> <p class="para"> This exists as of PHP 5.3.7. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-ssl-capath"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_SSL_CAPATH</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> The file path to the directory that contains the trusted SSL CA certificates, which are stored in PEM format. </p> <p class="para"> This exists as of PHP 5.3.7. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-ssl-cert"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_SSL_CERT</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> The file path to the SSL certificate. </p> <p class="para"> This exists as of PHP 5.3.7. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-cipher"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_SSL_CIPHER</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> A list of one or more permissible ciphers to use for SSL encryption, in a format understood by OpenSSL. For example: <em>DHE-RSA-AES256-SHA:AES128-SHA</em> </p> <p class="para"> This exists as of PHP 5.3.7. </p> </dd> </dt> <dt id="pdo.constants.mysql-attr-key"> <span class="term"> <strong><code>PDO::MYSQL_ATTR_SSL_KEY</code></strong> (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>) </span> <dd> <p class="para"> The file path to the SSL key. </p> <p class="para"> This exists as of PHP 5.3.7. </p> </dd> </dt> </dl> </div> <div class="section" id="pdo-mysql.configuration"> <h2 class="title">Runtime Configuration</h2> <p class="simpara"> The behaviour of these functions is affected by settings in <var class="filename">php.ini</var>. </p> <p class="para"> <table class="doctable table"> <caption><strong>PDO_MYSQL Configuration Options</strong></caption> <thead> <tr> <th>Name</th> <th>Default</th> <th>Changeable</th> </tr> </thead> <tbody class="tbody"> <tr> <td><a href="ref.pdo-mysql.html#ini.pdo-mysql.default-socket" class="link">pdo_mysql.default_socket</a></td> <td>"/tmp/mysql.sock"</td> <td>PHP_INI_SYSTEM</td> </tr> <tr> <td><a href="ref.pdo-mysql.html#ini.pdo-mysql.debug" class="link">pdo_mysql.debug</a></td> <td>NULL</td> <td>PHP_INI_SYSTEM</td> </tr> </tbody> </table> For further details and definitions of the PHP_INI_* modes, see the <a href="configuration.changes.modes.html" class="xref">Where a configuration setting may be set</a>. </p> <p class="para">Here's a short explanation of the configuration directives.</p> <p class="para"> <dl> <dt id="ini.pdo-mysql.default-socket"> <span class="term"> <em><code class="parameter">pdo_mysql.default_socket</code></em> <span class="type"><a href="language.types.string.html" class="type string">string</a></span> </span> <dd> <p class="para"> Sets a Unix domain socket. This value can either be set at compile time if a domain socket is found at configure. This ini setting is Unix only. </p> </dd> </dt> <dt id="ini.pdo-mysql.debug"> <span class="term"> <em><code class="parameter">pdo_mysql.debug</code></em> <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span> </span> <dd> <p class="para"> Enables debugging for PDO_MYSQL. This setting is only available when PDO_MYSQL is compiled against mysqlnd and in PDO debug mode. </p> </dd> </dt> </dl> </p> </div> </div> <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a> — Connecting to MySQL databases</li></ul> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-informix.connection.html">PDO_INFORMIX DSN</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a></div> <div class="up"><a href="pdo.drivers.html">PDO Drivers</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>