mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
9190379067
commit
f4fbe89e0e
1 changed files with 28 additions and 1 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue