Per a suggestion from Philip on IRC, show how to work around the charset DSN

parameter being ignored with pdo_mysql before PHP 5.3.6, based on a user note
by Davy Defaud.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@312154 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Adam Harvey 2011-06-14 15:08:42 +00:00
parent 9190379067
commit f4fbe89e0e

View file

@ -91,7 +91,34 @@
<term><constant>charset</constant></term>
<listitem>
<para>
The character set (since PHP 5.3.6).
The character set.
</para>
<para>
Prior to PHP 5.3.6, this element was silently ignored. The same
behaviour can be replicated with the
<constant>PDO::MYSQL_ATTR_INIT_COMMAND</constant> driver option, as
the following example shows.
</para>
<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>
</para>
</listitem>
</varlistentry>