#48293 [NEW]: PHP sometimes sends user name to mysql server in an incorrect encoding
| From: | aaa_whoknows_me at list dot ru | Date: | Fri, 15 May 2009 12:16:27 +0000 |
| Subject: | #48293 [NEW]: PHP sometimes sends user name to mysql server in an incorrect encoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-137368@lists.php.net to get a copy of this message | ||
From: aaa_whoknows_me at list dot ru
Operating system: Windows
PHP version: 5.3.0RC2
PHP Bug Type: MySQL related
Bug description: PHP sometimes sends user name to mysql server in an incorrect encoding
Description:
------------
PHP >= 5.3.0 sends user name to mysql server in an incorrect encoding in
some cases.
-----------------------
In this case PHP uses UTF-8 as its default encoding. PHP sends user name
in mysql server default encoding. But in some cases mysql uses different
encodings for data storing and sql queries. Consider a following
situation:
my.ini
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=ucs2
So, 'user' in UTF-8 == 'ôÈ' in UTF-16BE
Reproduce code:
---------------
$link = mysql_connect('user', 'password', 'database');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
---------------
try {
$dbh = new PDO('mysql:host=localhost;dbname=database', 'user',
'password');
foreach($dbh->query('SELECT id FROM users;') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
}
---------------
$mysqli = new mysqli('localhost', 'user', 'password',
'database');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT id FROM users;")) {
printf("Select returned %d rows.\n", $result->num_rows);
/* free result set */
$result->close();
}
$mysqli->close();
Expected result:
----------------
A successful connection to the mysql database.
Actual result:
--------------
Access denied for user 'ôÈ'@'localhost' (using password: YES)
--
Edit bug report at http://bugs.php.net/?id=48293&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48293&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48293&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48293&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48293&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48293&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48293&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48293&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48293&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48293&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48293&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48293&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48293&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48293&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48293&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48293&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48293&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48293&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48293&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48293&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48293&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48293&r=mysqlcfg