ID: 48293 Updated by: j...@php.net Reported By: aaa_whoknows_me at list dot ru -Status: Open +Status: Feedback Bug Type: MySQL related Operating System: Windows PHP Version: 5.3.0RC2 New Comment:
Just to make sure: This does not happen with PHP 5.2.9 ?? Previous Comments: ------------------------------------------------------------------------ [2009-05-15 12:16:27] aaa_whoknows_me at list dot ru 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 this bug report at http://bugs.php.net/?id=48293&edit=1