2014-09-05 07:44:07 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 08:37:21 +00:00
|
|
|
<!-- $Revision$ -->
|
2005-09-04 19:39:32 +00:00
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<reference xml:id="ref.pdo-mysql" xmlns="http://docbook.org/ns/docbook">
|
2013-05-23 17:38:21 +00:00
|
|
|
<?phpdoc extension-membership="bundledexternal" ?>
|
2005-08-12 02:03:50 +00:00
|
|
|
<title>MySQL Functions (PDO_MYSQL)</title>
|
2005-08-20 23:14:57 +00:00
|
|
|
<titleabbrev>MySQL (PDO)</titleabbrev>
|
2005-08-12 02:03:50 +00:00
|
|
|
<partintro>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<section xml:id="pdo-mysql.intro">
|
2005-08-12 02:03:50 +00:00
|
|
|
&reftitle.intro;
|
|
|
|
<para>
|
2007-12-31 15:43:38 +00:00
|
|
|
PDO_MYSQL is a driver that implements the <link linkend="intro.pdo">PHP
|
2005-09-11 06:17:09 +00:00
|
|
|
Data Objects (PDO) interface</link>
|
2018-04-23 22:12:13 +00:00
|
|
|
to enable access from PHP to MySQL databases.
|
2005-08-12 02:03:50 +00:00
|
|
|
</para>
|
2005-09-15 20:57:51 +00:00
|
|
|
<para>
|
2019-12-14 19:18:34 +00:00
|
|
|
As of PHP 5.2.1, PDO_MYSQL uses emulated prepares by default.
|
|
|
|
Formerly, PDO_MYSQL defaulted to native prepared statement support
|
|
|
|
present in MySQL 4.1 and higher, and emulated them for older versions of the
|
|
|
|
mysql client libraries.
|
2005-09-15 20:57:51 +00:00
|
|
|
</para>
|
2018-04-23 22:12:13 +00:00
|
|
|
|
|
|
|
<para>
|
|
|
|
<emphasis role="bold">MySQL 8</emphasis>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set
|
|
|
|
MySQL 8 Server's default password plugin to <emphasis>mysql_native_password</emphasis>
|
|
|
|
or else you will see errors similar to
|
|
|
|
<emphasis>The server requested authentication method unknown to the client [caching_sha2_password]</emphasis>
|
|
|
|
even when <emphasis>caching_sha2_password</emphasis> is not used.
|
|
|
|
</para>
|
|
|
|
<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 <literal>default_authentication_plugin=mysql_native_password</literal>
|
|
|
|
in <filename>my.cnf</filename>. The <emphasis>caching_sha2_password</emphasis>
|
|
|
|
plugin will be supported in a future PHP release. In the meantime, the
|
|
|
|
<link linkend="book.mysql-xdevapi">mysql_xdevapi</link> extension does
|
|
|
|
support it.
|
|
|
|
</para>
|
|
|
|
|
2005-09-15 20:57:51 +00:00
|
|
|
<warning>
|
|
|
|
<para>
|
2005-11-27 06:51:40 +00:00
|
|
|
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
|
2005-09-15 20:57:51 +00:00
|
|
|
commit any pending transactions.
|
|
|
|
</para>
|
|
|
|
</warning>
|
2005-08-12 02:03:50 +00:00
|
|
|
</section>
|
2011-01-26 22:48:38 +00:00
|
|
|
&reference.pdo-mysql.configure;
|
2005-09-15 20:57:51 +00:00
|
|
|
&reference.pdo-mysql.constants;
|
2010-10-20 21:32:11 +00:00
|
|
|
&reference.pdo-mysql.ini;
|
2005-08-12 02:03:50 +00:00
|
|
|
</partintro>
|
|
|
|
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="ref.pdo-mysql.connection">
|
2005-08-12 02:03:50 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>PDO_MYSQL DSN</refname>
|
|
|
|
<refpurpose>Connecting to MySQL databases</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
|
|
|
<para>
|
|
|
|
The PDO_MYSQL Data Source Name (DSN) is composed of the following elements:
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>DSN prefix</term>
|
|
|
|
<listitem>
|
2005-08-12 03:31:18 +00:00
|
|
|
<para>
|
|
|
|
The DSN prefix is <userinput>mysql:</userinput>.
|
|
|
|
</para>
|
2005-08-12 02:03:50 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2012-02-29 05:03:14 +00:00
|
|
|
<term><literal>host</literal></term>
|
2005-08-12 02:03:50 +00:00
|
|
|
<listitem>
|
2005-08-12 03:31:18 +00:00
|
|
|
<para>
|
|
|
|
The hostname on which the database server resides.
|
|
|
|
</para>
|
2005-08-12 02:03:50 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2005-12-13 19:37:44 +00:00
|
|
|
<varlistentry>
|
2012-02-29 05:03:14 +00:00
|
|
|
<term><literal>port</literal></term>
|
2005-12-13 19:37:44 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The port number where the database server is listening.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2005-08-12 02:03:50 +00:00
|
|
|
<varlistentry>
|
2012-02-29 05:03:14 +00:00
|
|
|
<term><literal>dbname</literal></term>
|
2005-08-12 02:03:50 +00:00
|
|
|
<listitem>
|
2005-08-12 03:31:18 +00:00
|
|
|
<para>
|
|
|
|
The name of the database.
|
|
|
|
</para>
|
2005-08-12 02:03:50 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2005-12-13 19:37:44 +00:00
|
|
|
<varlistentry>
|
2012-02-29 05:03:14 +00:00
|
|
|
<term><literal>unix_socket</literal></term>
|
2005-12-13 19:37:44 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2007-02-15 09:24:37 +00:00
|
|
|
The MySQL Unix socket (shouldn't be used with <literal>host</literal>
|
2005-12-13 19:37:44 +00:00
|
|
|
or <literal>port</literal>).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2010-10-10 09:04:45 +00:00
|
|
|
<varlistentry>
|
2012-02-29 05:03:14 +00:00
|
|
|
<term><literal>charset</literal></term>
|
2010-10-10 09:04:45 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-06-08 05:21:09 +00:00
|
|
|
The character set. See the <link linkend="mysqlinfo.concepts.charset">character set</link>
|
|
|
|
concepts documentation for more information.
|
2011-06-14 15:08:42 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Prior to PHP 5.3.6, this element was silently ignored. The same
|
2011-06-14 16:29:46 +00:00
|
|
|
behaviour can be partly replicated with the
|
2011-06-14 15:08:42 +00:00
|
|
|
<constant>PDO::MYSQL_ATTR_INIT_COMMAND</constant> driver option, as
|
|
|
|
the following example shows.
|
|
|
|
</para>
|
2011-06-14 16:29:46 +00:00
|
|
|
<warning>
|
|
|
|
<simpara>
|
|
|
|
The method in the below example can only be used with character sets
|
|
|
|
that share the same lower 7 bit representation as ASCII, such as
|
|
|
|
ISO-8859-1 and UTF-8. Users using character sets that have different
|
|
|
|
representations (such as UTF-16 or Big5) <emphasis>must</emphasis>
|
2012-02-29 05:03:14 +00:00
|
|
|
use the <literal>charset</literal> option provided in PHP 5.3.6
|
2011-06-14 16:29:46 +00:00
|
|
|
and later versions.
|
|
|
|
</simpara>
|
|
|
|
</warning>
|
2011-06-14 15:08:42 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>
|
|
|
|
Setting the connection character set to UTF-8 prior to PHP 5.3.6
|
|
|
|
</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$dsn = 'mysql:host=localhost;dbname=testdb';
|
|
|
|
$username = 'username';
|
|
|
|
$password = 'password';
|
|
|
|
$options = array(
|
|
|
|
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
|
|
|
);
|
|
|
|
|
|
|
|
$dbh = new PDO($dsn, $username, $password, $options);
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2010-10-10 09:04:45 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2005-08-12 02:03:50 +00:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2010-10-20 08:15:25 +00:00
|
|
|
|
2005-08-12 02:03:50 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>PDO_MYSQL DSN examples</title>
|
|
|
|
<para>
|
|
|
|
The following example shows a PDO_MYSQL DSN for connecting to
|
|
|
|
MySQL databases:
|
2005-12-13 19:37:44 +00:00
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2005-08-12 02:03:50 +00:00
|
|
|
mysql:host=localhost;dbname=testdb
|
2005-12-13 19:37:44 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
More complete examples:
|
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
|
|
|
mysql:host=localhost;port=3307;dbname=testdb
|
|
|
|
mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
|
2005-08-12 02:03:50 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2010-10-20 08:15:25 +00:00
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
|
|
<title>Unix only:</title>
|
|
|
|
<para>
|
2010-10-20 09:15:48 +00:00
|
|
|
When the host name is set to <literal>"localhost"</literal>, then the connection to the
|
2013-03-26 03:57:46 +00:00
|
|
|
server is made thru a domain socket. If PDO_MYSQL is compiled against libmysqlclient then the
|
|
|
|
location of the socket file is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled
|
2010-10-20 09:15:48 +00:00
|
|
|
against mysqlnd a default socket can be set thru the <link linkend="ini.pdo-mysql.default-socket">
|
2010-10-20 08:15:25 +00:00
|
|
|
pdo_mysql.default_socket</link> setting.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
|
2005-08-12 02:03:50 +00:00
|
|
|
</reference>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2005-08-12 02:03:50 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|