Re-mysql coding problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.