简体   繁体   中英

sql query with LIKE

I have a weird problem please take a look at this query:

select * from myfriend where name like "%n%";

when execute this query on phpMyAdmin the query returned correct results, but when execute it using php no result returned.

please note this query executed in drupal 6.

what is the problem with char "n" and PHP?

百分号在Drupal 6查询中用作占位符,因此您需要转义它们:

$query = db_query('select * from myfriend where name like "%%n%%"');
$searchChar = "n";

$query = "SELECT * FROM `myfriend` WHERE `name` LIKE '%" . $searchChar . "%'";

Then use the $query variable in your statement.

Eg:

$mysql->query($query);

mysql_query($query);

Your query is perfect. Give some brief on it. You can check if your connection of database from php to mysql is correct. You can echo that query from php file and run into phpmyadmin if that gives correct output then surely database connectivity problem will be there.

There is absolutely no issues with any character in php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM