On 01/07/2011 03:39 PM, Kalle Sommer Nielsen wrote:
> kalle                                    Fri, 07 Jan 2011 14:39:56 +0000
> 
> Revision: http://svn.php.net/viewvc?view=revision&revision=307224
> 
> Log:
> Implemented FR #47802, support for character sets in DSN strings for PDO_MYSQL
> 
> Bug: http://bugs.php.net/47802 (Open) PDO_MYSQL doesn't use the charset 
> parameter
>       
> Changed paths:
>     U   php/php-src/trunk/NEWS
>     U   php/php-src/trunk/UPGRADING
>     U   php/php-src/trunk/ext/pdo_mysql/mysql_driver.c
>     U   php/php-src/trunk/ext/pdo_mysql/php_pdo_mysql_int.h
> 
> Modified: php/php-src/trunk/NEWS
> ===================================================================
> --- php/php-src/trunk/NEWS    2011-01-07 14:22:30 UTC (rev 307223)
> +++ php/php-src/trunk/NEWS    2011-01-07 14:39:56 UTC (rev 307224)
> @@ -170,6 +170,10 @@
>    . Added nextRowset support.
>    . Fixed bug #50755 (PDO DBLIB Fails with OOM).
> 
> +- Improved PDO MySQL:
> +  . Implemented FR #47802 (Support for setting character sets in DSN 
> strings).
> +    (Kalle)
> +
>  - Improved Reflection extension: (Johannes)
>    . Added ReflectionExtension::isTemporary() and
>      ReflectionExtension::isPersistent() methods.
> 
> Modified: php/php-src/trunk/UPGRADING
> ===================================================================
> --- php/php-src/trunk/UPGRADING       2011-01-07 14:22:30 UTC (rev 307223)
> +++ php/php-src/trunk/UPGRADING       2011-01-07 14:39:56 UTC (rev 307224)
> @@ -161,6 +161,8 @@
>    strings. This breaks code that iterated the resulting stream array using a
>    numeric index, but makes easier to identify which of the passed streams are
>    present in the result.
> +- pdo_mysql now supports setting character sets when connecting in the DSN
> +  string.
> 
> 
>  ===================================
> 
> Modified: php/php-src/trunk/ext/pdo_mysql/mysql_driver.c
> ===================================================================
> --- php/php-src/trunk/ext/pdo_mysql/mysql_driver.c    2011-01-07 14:22:30 UTC 
> (rev 307223)
> +++ php/php-src/trunk/ext/pdo_mysql/mysql_driver.c    2011-01-07 14:39:56 UTC 
> (rev 307224)
> @@ -711,6 +711,13 @@
>               goto cleanup;
>       }
> 
> +#ifdef PDO_MYSQL_HAS_CHARSET
> +     if (vars[0].optval && mysql_set_character_set(H->server, 
> vars[0].optval)) {
> +             pdo_mysql_error(dbh);
> +             goto cleanup;
> +     }
> +#endif
> +
>       if (!dbh->auto_commit) {
>               mysql_handle_autocommit(dbh TSRMLS_CC);
>       }
> 
> Modified: php/php-src/trunk/ext/pdo_mysql/php_pdo_mysql_int.h
> ===================================================================
> --- php/php-src/trunk/ext/pdo_mysql/php_pdo_mysql_int.h       2011-01-07 
> 14:22:30 UTC (rev 307223)
> +++ php/php-src/trunk/ext/pdo_mysql/php_pdo_mysql_int.h       2011-01-07 
> 14:39:56 UTC (rev 307224)
> @@ -33,6 +33,10 @@
>  #    define PDO_MYSQL_PARAM_BIND MYSQL_BIND
>  #endif
> 
> +#if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || 
> MYSQL_VERSION_ID >= 50007 || defined(MYSQL_USE_MYSQLND)
> +# define PDO_MYSQL_HAS_CHARSET
> +#endif
> +
>  #if defined(PDO_USE_MYSQLND) && PHP_DEBUG && !defined(PHP_WIN32)
>  #define PDO_DBG_ENABLED 1
> 
> 
> 

this fix is inefficient. Implies a query to the server. Much efficient
is using mysql_options() on a MYSQL handle after mysql_init() but before
mysql_real_connect() (which sets the charset during the handshake).

http://dev.mysql.com/doc/refman/5.5/en/mysql-options.html
MYSQL_SET_CHARSET_NAME (argument type: char *)

The name of the character set to use as the default character set.

Could you change it?

Thanks!
Andrey

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to