When using PHP 5.3.0 with MySQL 5.1.3, different installation methods result in different default character set behaviors when connecting to MySQL without explicitly setting encoding.
Two PHP environments with identical versions but different installation methods:
1. Yum-installed PHP 5.3.0 with MySQL 5.1.3 (my.ini configured with character_set_server=utf8)
2. Manually compiled PHP 5.3.0
Both environments connect to the same MySQL server using mysql_connect() without setting mysql_query("set names utf8") or mysql_set_charset("utf8"). However, they use different default connection character sets.
The following PHP code demonstrates how to check MySQL character variables:
Yum-installed PHP output:
Array
(
[Variable_name] => character_set_client
[Value] => latin1
)
Array
(
[Variable_name] => character_set_connection
[Value] => latin1
)
Array
(
[Variable_name] => character_set_database
[Value] => utf8
)
Array
(
[Variable_name] => character_set_filesystem
[Value] => binary
)
Array
(
[Variable_name] => character_set_results
[Value] => latin1
)
Array
(
[Variable_name] => character_set_server
[Value] => utf8
)
Array
(
[Variable_name] => character_set_system
[Value] => utf8
)
Manually compiled PHP output:
Array
(
[Variable_name] => character_set_client
[Value] => utf8
)
Array
(
[Variable_name] => character_set_connection
[Value] => utf8
)
Array
(
[Variable_name] => character_set_database
[Value] => utf8
)
Array
(
[Variable_name] => character_set_filesystem
[Value] => binary
)
Array
(
[Variable_name] => character_set_results
[Value] => utf8
)
Array
(
[Variable_name] => character_set_server
[Value] => utf8
)
Array
(
[Variable_name] => character_set_system
[Value] => utf8
)
Examining the compilation parameters through phpinfo() reveals the cause:
For yum-installed PHP:
--with-mysql=shared,/usr --with-mysqli=shared,/usr/lib64/mysql/mysql_config
These extensions use the MySQL Client Library by default. When installed on Linux, this requires the MySQL client package.
For compiled PHP:
div>--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd