Just write a little program to do a mysql escape string test, but the result is wrong.
The Code is below:
The correct result (Under 5.4.29) is
But the result in 5.3.28 is
The above code is working in PHP 5.4.29 but not working in 5.3.28_2. I also write a python program to do a test and the result is correct.
I think the port 5.3.28 might have something wrong cause this issue.
The Code is below:
Code:
<?php
// A55C is a valid multibyte big5
$city = pack("H*", "A55C");
$mysqli = new mysqli( $db_host, $user, $pass, $dbname);
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if(!$mysqli->set_charset("big5")) {
printf("Error loading character set big5: %s\n", $mysqli->error);
}
$city1 = ($mysqli->real_escape_string($city));
$c1_charset = $mysqli->get_charset()->charset;
print "Charset is:$c1_charset and A55C is $city1 and ". bin2hex($city1) ." \n";
?>
The correct result (Under 5.4.29) is
Code:
Charset is:big5 and A55C is 功 and hex code is a55c
Code:
Charset is:big5 and A55C is 功\ and a55c5c
The above code is working in PHP 5.4.29 but not working in 5.3.28_2. I also write a python program to do a test and the result is correct.
Code:
db = MySQLdb.connect(host=db_host, # your host, usually localhost
user=dbuser, # your username
passwd=dbpass, # your password
charset="big5",
db=dbname) # name of the data base
print db.get_character_set_info()
dec = db.escape_string("A55C".decode("hex"))
dechex = dec.encode("hex")
print "A55C escape_string is "+dec+ ", and decode is "+dechex