$sql = sprintf( "SELECT topic_title
FROM `phpbb_topics`
WHERE `topic_title` LIKE '%%%s%%' LIMIT 20"
, mysql_real_escape_string('match this title')
);
我在 phpMyAdmin 中运行此查询的结果是:(正确)
match this title
match this title 002
但是当我在 PHP 中运行相同的 MYSQL 查询时,我得到:(不正确)
match this title 002
我也尝试过 MATCH AGAINST,结果与 php 和 phpMyAdmin 相同:
$sql = "SELECT topic_title
FROM phpbb_topics
WHERE MATCH (topic_title)
AGAINST('match this title' IN BOOLEAN MODE)";
我用来搜索的整个代码块:
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("phpbb") or die(mysql_error());
$query = "match this title";
$query = "SELECT topic_title
FROM phpbb_topics
WHERE MATCH (topic_title)
AGAINST('$query' IN BOOLEAN MODE)";
// Doesn't work (these 2 both give the same result "match this title 002" and no the "match this title")
// $query = "SELECT * FROM `phpbb_topics`
// WHERE `topic_title`
// LIKE '%$query%'
// LIMIT 0, 30 "; // Doesn't work
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$topic_title = $row['topic_title'];
echo "$topic_title";
}
关于我做错了什么的任何想法?
我一直在到处寻找,几乎没有发现任何帮助:(