summaryrefslogtreecommitdiff
blob: e85e43ca4a3d708a5248eb89950cbf64c1318edb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--- mysql_driver.c	2006-12-02 12:43:22.000000000 +0100
+++ mysql_driver.c	2006-12-02 12:43:39.000000000 +0100
@@ -408,6 +408,7 @@
 	pdo_mysql_db_handle *H;
 	int i, ret = 0;
 	char *host = NULL, *unix_socket = NULL;
+	char *connect_charset = NULL;
 	unsigned int port = 3306;
 	char *dbname;
 	struct pdo_data_src_parser vars[] = {
@@ -528,6 +529,13 @@
 	if (vars[2].optval && !strcmp("localhost", vars[2].optval)) {
 		unix_socket = vars[4].optval;  
 	}
+
+	connect_charset = PDOMYSQLG(connect_charset);
+
+	if (connect_charset != NULL) {
+		mysql_options(H->server, MYSQL_SET_CHARSET_NAME, connect_charset);
+	}
+
 	if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) {
 		pdo_mysql_error(dbh);
 		goto cleanup;
--- pdo_mysql.c	2006-12-02 12:43:22.000000000 +0100
+++ pdo_mysql.c	2006-12-02 12:43:39.000000000 +0100
@@ -30,6 +30,8 @@
 #include "php_pdo_mysql.h"
 #include "php_pdo_mysql_int.h"
 
+ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql)
+
 /* {{{ pdo_mysql_functions[] */
 zend_function_entry pdo_mysql_functions[] = {
 	{NULL, NULL, NULL}
@@ -69,12 +71,24 @@
 ZEND_GET_MODULE(pdo_mysql)
 #endif
 
+PHP_INI_BEGIN()
+	STD_PHP_INI_ENTRY("pdo_mysql.connect_charset",	NULL,	PHP_INI_ALL,	OnUpdateString,	connect_charset,	zend_pdo_mysql_globals,	pdo_mysql_globals)
+PHP_INI_END()
+
+static void php_pdo_mysql_init_globals(zend_pdo_mysql_globals *pdo_mysql_globals)
+{
+	pdo_mysql_globals->connect_charset = NULL;
+}
+
 /* true global environment */
 
 /* {{{ PHP_MINIT_FUNCTION
  */
 PHP_MINIT_FUNCTION(pdo_mysql)
 {
+	ZEND_INIT_MODULE_GLOBALS(pdo_mysql, php_pdo_mysql_init_globals, NULL);
+	REGISTER_INI_ENTRIES();
+
 	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
 	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (long)PDO_MYSQL_ATTR_LOCAL_INFILE);
 	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND);
@@ -91,6 +105,7 @@
  */
 PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
 {
+	UNREGISTER_INI_ENTRIES();
 	php_pdo_unregister_driver(&pdo_mysql_driver);
 	return SUCCESS;
 }
@@ -103,6 +118,8 @@
 	php_info_print_table_start();
 	php_info_print_table_header(2, "PDO Driver for MySQL, client library version", mysql_get_client_info());
 	php_info_print_table_end();
+
+	DISPLAY_INI_ENTRIES();
 }
 /* }}} */
 
--- php_pdo_mysql.h	2006-12-02 12:43:22.000000000 +0100
+++ php_pdo_mysql.h	2006-12-02 13:04:41.000000000 +0100
@@ -40,6 +40,18 @@
 PHP_RSHUTDOWN_FUNCTION(pdo_mysql);
 PHP_MINFO_FUNCTION(pdo_mysql);
 
+ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
+	char	*connect_charset;
+ZEND_END_MODULE_GLOBALS(pdo_mysql)
+
+#ifdef ZTS
+# define PDOMYSQLG(v) TSRMG(pdo_mysql_globals_id, zend_pdo_mysql_globals *, v)
+#else
+# define PDOMYSQLG(v) (pdo_mysql_globals.v)
+#endif
+
+ZEND_EXTERN_MODULE_GLOBALS(pdo_mysql)
+
 #endif	/* PHP_PDO_MYSQL_H */