|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-08-04 13:31 UTC] bogdan dot enache at intersat-telecom dot ro
 Description:
------------
A query like:
SELECT * FROM view_cl_all WHERE cl_name LIKE '%ab%'
is working both in Query Browser and PHP. BUT,
SELECT * FROM view_cl_all WHERE cl_name LIKE '%ab%' COLLATE utf8_general_ci
works (5 results) in Query Browser. If I run the same query in PHP, query fails (returns NULL resultset).
Table type: InnoDB, charset: UTF8, collation: utf8_romanian_ci
Reproduce code:
---------------
So I have this PHP code:
if ($dbc->query($s)){
$ret = array();
if($res = $dbc->store_result()){
$no = $res->num_rows;
for($i = 0; $i < $no; $i++){
$ret[$i] = $res->fetch_assoc();
}
if($res){
$res->close();
}
return $ret;
}
}
else{
echo 'Query failed: '; var_dump($s);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
}
exit;
return FALSE;
}
IF I set 
$s="SELECT * FROM view_cl_all WHERE (cl_name LIKE '%al%' )"
it's working, i get a number of results.
But if 
$s="SELECT * FROM view_cl_all WHERE (cl_name LIKE '%al%' COLLATE utf8_general_ci)"
then query silently fails, no error, but NULL resultset.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 20:00:01 2025 UTC | 
Create test table in MySQL: //////////////// CREATE TABLE `t1` ( `id` INTEGER UNSIGNED NOT NULL DEFAULT NULL AUTO_INCREMENT, `s1` VARCHAR(45) NOT NULL DEFAULT '', PRIMARY KEY(`id`) ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_romanian_ci; INSERT INTO t1(s1) values ('ă?şţ?Ă?ŞŢ?'); INSERT INTO t1(s1) values ('qwertzuiop'); //////////////// PHP script to test: <?php $dbc = new mysqli("?", "?", "?", "?"); $s1 = "SELECT * FROM t1 WHERE s1 LIKE '%qw%';"; $s2 = "SELECT * FROM t1 WHERE s1 LIKE '%ista%' COLLATE utf8_general_ci;"; if ($res = $dbc->query($s1)) { $row = $res->fetch_assoc(); echo 'Query 1: '; var_dump($row); $res->close(); } if ($res = $dbc->query($s2)) { $row = $res->fetch_assoc(); var_dump($row); $res->close(); } else{ echo "Query 2 failed"; } $dbc->close(); ?>Please replace INSERT INTO t1(s1) values ('ă?şţ?Ă?ŞŢ?'); with: INSERT INTO t1(s1) values (x'C483C3AEC59FC5A3C3A2C482C38EC59EC5A2C382'); because the bug reporting system apparently can't escape unicode correctly.Already tried that, but I get: Fatal error: Call to undefined method mysqli::set_charset() in D:\_webroot\root\t1.php on line 9 /////////////////////////////////////////////////////// <?php $mysqli = new mysqli("localhost", "root", "webdev", "test"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if (!$mysqli->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); } else { printf("Current character set: %s\n", $mysqli->character_set_name()); } $s1 = "SELECT * FROM t1 WHERE s1 LIKE '%qw%';"; $s2 = "SELECT * FROM t1 WHERE s1 LIKE '%ista%' COLLATE utf8_general_ci;"; if ($res = $mysqli->query($s1)) { $row = $res->fetch_assoc(); echo 'Query 1: '; var_dump($row); $res->close(); } if ($res = $mysqli->query($s2)) { $row = $res->fetch_assoc(); var_dump($row); $res->close(); } else{ echo "Query 2 failed"; } $mysqli->close(); ?> //////////////////////////// I use mysql 5.0.22, PHP 5.1.4. Tried this with both libmysql.dll from the PHP distro, and the latest libmysql.dll available from MySQL site ( http://dev.mysql.com/downloads/connector/php/ ). Method is not recognized....