Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 11825

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!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 databases.
    </p>
    <p class="para">
     PDO_MYSQL will take advantage of native prepared statement support
     present in MySQL 4.1 and higher.  If you&#039;re using an older version of the
     mysql client libraries, PDO will emulate them for you.
    </p>

    <p class="para">
      <em class="emphasis">MySQL 8</em>
    </p>

    <p class="para">
     When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set 
     MySQL 8 Server&#039;s default password plugin to <em class="emphasis">mysql_native_password</em>
     or else you will see errors similar to
     <em class="emphasis">The server requested authentication method unknown to the client [caching_sha2_password]</em>
     even when <em class="emphasis">caching_sha2_password</em> is not used.
    </p>
    <p class="para">
     This is because MySQL 8 defaults to caching_sha2_password, a plugin that is
     not recognized by the older PHP (mysqlnd) releases. Instead, change it by
     setting <em>default_authentication_plugin=mysql_native_password</em>
     in <var class="filename">my.cnf</var>. The <em class="emphasis">caching_sha2_password</em>
     plugin will be supported in a future PHP release. In the meantime, the
     <a href="book.mysql-xdevapi.html" class="link">mysql_xdevapi</a> extension does
     support it.
    </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">
  The common Unix distributions include binary versions of PHP that can
  be installed. Although these binary versions are typically built with
  support for the MySQL extensions, the extension libraries
  themselves may need to be installed using an additional package. Check
  the package manager than comes with your chosen distribution for
  availability.
 </p>
 
 <p class="para">
  For example, on Ubuntu the <em>php5-mysql</em> package installs
  the ext/mysql, ext/mysqli, and PDO_MYSQL PHP extensions. On CentOS, 
  the <em>php-mysql</em> package also installs these three 
  PHP extensions.
 </p>

 <p class="para">
  Alternatively, you can compile this extension yourself. Building PHP from 
  source allows you to specify the MySQL extensions you want to use, as well 
  as your choice of client library for each extension.
 </p>

 <p class="para">
  When compiling, 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 library. As of PHP 5.4, <a href="book.mysqlnd.html" class="link">mysqlnd</a>
  is the default library. For details about choosing a library, see
  <a href="mysqlinfo.library.choosing.html" class="link">Choosing a MySQL library</a>.
 </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">&raquo;&nbsp;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">&raquo;&nbsp;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>
      <a href="book.mysqlnd.html" class="link">mysqlnd</a> became the default MySQL library 
      when compiling PDO_MYSQL. Previously, libmysqlclient was the default MySQL library.
     </td>
    </tr>

    <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">
    <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>)
   </dt>

   <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&#039;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-1099"><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">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</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">)&nbsp;==&nbsp;</span><span style="color: #DD0000">'mysql'</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'select&nbsp;*&nbsp;from&nbsp;foo'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">MYSQL_ATTR_USE_BUFFERED_QUERY&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"my&nbsp;application&nbsp;only&nbsp;works&nbsp;with&nbsp;mysql;&nbsp;I&nbsp;should&nbsp;use&nbsp;\$stmt-&gt;fetchAll()&nbsp;instead"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div>
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-local-infile">
    <strong><code>PDO::MYSQL_ATTR_LOCAL_INFILE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Enable <em>LOAD LOCAL INFILE</em>.
    </p>
    <p class="para">
     Note, this constant can only be used in the <code class="parameter">driver_options</code> 
     array when constructing a new database handle.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-init-command">
    <strong><code>PDO::MYSQL_ATTR_INIT_COMMAND</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 <code class="parameter">driver_options</code> 
     array when constructing a new database handle.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-read-default-file">
    <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>)
   </dt>

   <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 id="pdo.constants.mysql-attr-read-default-group">
    <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>)
   </dt>

   <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 id="pdo.constants.mysql-attr-max-buffer-size">
    <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>)
   </dt>

   <dd>

    <p class="para">
     Maximum buffer size. Defaults to 1 MiB. This constant is not supported when 
     compiled against mysqlnd.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-direct-query">
    <strong><code>PDO::MYSQL_ATTR_DIRECT_QUERY</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Perform direct queries, don&#039;t use prepared statements.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-found-rows">
    <strong><code>PDO::MYSQL_ATTR_FOUND_ROWS</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Return the number of found (matched) rows, not the 
     number of changed rows.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-ignore-space">
    <strong><code>PDO::MYSQL_ATTR_IGNORE_SPACE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Permit spaces after function names. Makes all functions 
     names reserved words.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-compress">
    <strong><code>PDO::MYSQL_ATTR_COMPRESS</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Enable network communication compression. This is also supported when 
     compiled against mysqlnd as of PHP 5.3.11.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-ssl-ca">
    <strong><code>PDO::MYSQL_ATTR_SSL_CA</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 id="pdo.constants.mysql-attr-ssl-capath">
    <strong><code>PDO::MYSQL_ATTR_SSL_CAPATH</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 id="pdo.constants.mysql-attr-ssl-cert">
    <strong><code>PDO::MYSQL_ATTR_SSL_CERT</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 id="pdo.constants.mysql-attr-cipher">
    <strong><code>PDO::MYSQL_ATTR_SSL_CIPHER</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 id="pdo.constants.mysql-attr-key">
    <strong><code>PDO::MYSQL_ATTR_SSL_KEY</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <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 id="pdo.constants.mysql-attr-ssl-verify-server-cert">
    <strong><code>PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Provides a way to disable verification of the server SSL certificate.
    </p>
    <p class="para">
     This exists as of PHP  7.0.18 and PHP 7.1.4.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-multi-statements">
    <strong><code>PDO::MYSQL_ATTR_MULTI_STATEMENTS</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Disables multi query execution in both <span class="function"><a href="pdo.prepare.html" class="function">PDO::prepare()</a></span>
     and <span class="function"><a href="pdo.query.html" class="function">PDO::query()</a></span> when set to <strong><code>FALSE</code></strong>.
    </p>
    <p class="para">
     Note, this constant can only be used in the <code class="parameter">driver_options</code> 
     array when constructing a new database handle.
    </p>
    <p class="para">
     This exists as of PHP  5.5.21 and PHP 5.6.5.
    </p>
   </dd>

  

 </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>&quot;/tmp/mysql.sock&quot;</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&#039;s a short explanation of
the configuration directives.</p>

 <p class="para">
  <dl>

   
    <dt id="ini.pdo-mysql.default-socket">
     <code class="parameter">pdo_mysql.default_socket</code>
     <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    </dt>

    <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 id="ini.pdo-mysql.debug">
     <code class="parameter">pdo_mysql.debug</code>
     <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span>
    </dt>

    <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>

   
  </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>