]> granicus.if.org Git - php/commitdiff
MFT: Implemented FR #47802 (Support for setting character sets in DSN strings)
authorKalle Sommer Nielsen <kalle@php.net>
Mon, 17 Jan 2011 09:54:22 +0000 (09:54 +0000)
committerKalle Sommer Nielsen <kalle@php.net>
Mon, 17 Jan 2011 09:54:22 +0000 (09:54 +0000)
NEWS
ext/pdo_mysql/mysql_driver.c
ext/pdo_mysql/php_pdo_mysql_int.h
ext/pdo_mysql/tests/mysql_pdo_test.inc
ext/pdo_mysql/tests/pdo_mysql_connect_charset.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 3d72f72d5185a547a73280301afac918f5386548..c1fce02078779c7549a067b74031f6c7693d0e76 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,8 @@
     server mode. (Gustavo)
 
 - PDO MySQL driver:
+  . Implemented FR #47802 (Support for setting character sets in DSN strings). 
+    (Kalle)
   . Fixed bug #53551 (PDOStatement execute segfaults for pdo_mysql driver).
     (Johannes)
 
index c94ac695306221690530ced850f22b6027b7ff1a..e32d9224f050de87bf34f81df590a6f6bb476689 100755 (executable)
@@ -711,6 +711,13 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
 #endif
        }
 
+#ifdef PDO_MYSQL_HAS_CHARSET
+       if (vars[0].optval && mysql_options(H->server, MYSQL_SET_CHARSET_NAME, vars[0].optval)) {
+               pdo_mysql_error(dbh);
+               goto cleanup;
+       }
+#endif
+
        dbname = vars[1].optval;
        host = vars[2].optval;  
        if(vars[3].optval) {
index 6192b7238d3a3b31b778ac66db61684487d74261..94ab41fddc1162c01f14e0415ee16c1b115b9875 100755 (executable)
 #      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
 
index 01c4cb9aafb02cc7796a9e969e8725871388a529..a3ffd5b9ccb3879e71c6361c6a07a8b138e47f92 100644 (file)
@@ -4,9 +4,9 @@ require_once(dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc');
 
 class MySQLPDOTest extends PDOTest {
 
-       static function factory($classname = 'PDO', $drop_test_tables = false, $myattr = null) {
+       static function factory($classname = 'PDO', $drop_test_tables = false, $myattr = null, $mydsn = null) {
 
-               $dsn    = self::getDSN();
+               $dsn    = self::getDSN($mydsn);
                $user   = PDO_MYSQL_TEST_USER;
                $pass   = PDO_MYSQL_TEST_PASS;
                $attr   = getenv('PDOTEST_ATTR');
diff --git a/ext/pdo_mysql/tests/pdo_mysql_connect_charset.phpt b/ext/pdo_mysql/tests/pdo_mysql_connect_charset.phpt
new file mode 100644 (file)
index 0000000..b7e6ab4
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--\r
+PDO_MYSQL: Defining a connection charset in the DSN\r
+--SKIPIF--\r
+<?php\r
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');\r
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');\r
+MySQLPDOTest::skip();\r
+?>\r
+--FILE--\r
+<?php\r
+       /* TODO: remove this test after fix and enable the BIT test in pdo_mysql_types.phpt again */\r
+       require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');\r
+\r
+       /* Connect to mysql to determine the current charset so we can diffinate it */\r
+       $link           = MySQLPDOTest::factory();\r
+       $charset        = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value;\r
+\r
+       /* Make sure that we don't attempt to set the current character set to make this case useful */\r
+       $new_charset    = ($charset == 'latin1' ? 'ascii' : 'latin1');\r
+\r
+       /* Done with the original connection, create a second link to test the character set being defined */\r
+       unset($link);\r
+\r
+       $link           = MySQLPDOTest::factory('PDO', false, null, Array('charset' => $new_charset));\r
+       $conn_charset   = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value;\r
+\r
+       if ($charset !== $conn_charset) {\r
+               echo "done!\n";\r
+       } else {\r
+               echo "failed!\n";\r
+       }\r
+?>\r
+--EXPECTF--\r
+done!
\ No newline at end of file