Yum Install version php5.3.0
+ mysql5.1.3 (My.ini--->character_set_server=utf8)
Compiling and installing php5.3.0
The above means: two different PHP environments, one compiled install a Yum installation, the same version, when using the Mysql_connect () method to connect the same MySQL,
Without setting mysql_query ("Set names UTF") or Mysql_set_charset ("UTF8"), they use a different library encoding by default
<? PHP $link=mysql_connectdie (mysql_error());
$res=mysql_query("Show variables like '%char% '");
while ($arr=mysql_fetch_assoc($res)) { var_dump($arr );}
Yum version php
Array' Variable_name ' =string' Character_set_client ' (length=20) ' Value ' =string' Latin1 ' (length=6)Array' Variable_name ' =string' Character_set_connection ' (length=24) ' Value ' =string' Latin1 ' (length=6)Array' Variable_name ' =string' Character_set_database ' (length=22) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_filesystem ' (length=24) ' Value ' =string' Binary ' (length=6)Array' Variable_name ' =string' Character_set_results ' (length=21) ' Value ' =string' Latin1 ' (length=6)Array' Variable_name ' =string' Character_set_server ' (length=20) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_system ' (length=20) ' Value ' =string' UTF8 ' (length=4)
Manually compiled version of PHP
Array' Variable_name ' =string' Character_set_client ' (length=20) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_connection ' (length=24) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_database ' (length=22) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_filesystem ' (length=24) ' Value ' =string' Binary ' (length=6)Array' Variable_name ' =string' Character_set_results ' (length=21) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_server ' (length=20) ' Value ' =string' UTF8 ' (length=4)Array' Variable_name ' =string' Character_set_system ' (length=20) ' Value ' =string' UTF8 ' (length=4)
Find the cause of the problem by viewing the compilation parameters of two different PHP environments via Phpinfo ():
In the Yum version of PHP
--with-mysql=shared,/usr '--with-mysqli=shared,/usr/lib64/mysql/mysql_config '
These two libraries are called by default in the MySQL client library (by default the MySQL database extensions is configured to use MySQL client library literal translation), this time Linux is required To install MySQL, but
PHP compiled version
--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd
With the MYSQLND (Specific role Baidu,google)
The biggest difference between the two is that when Mysqlnd connects to a database, the default is to use the encoding shown by the MySQL server-side show global variables like "%char%"
And the other is always using latin1 as a library encoding, equivalent to virtually, has been set up a "set names Latin1"
Re-mysql coding problem