1
$sql = sprintf("SELECT topic_title
FROM `phpbb_topics`
WHERE `topic_title` LIKE '%%%s%%' LIMIT 20"
, mysql_real_escape_string('match this title')
);
这我运行此查询在phpMyAdmin的结果是:(正确的)搜索PHPBB的通过MYSQL PHP“TOPIC_TITLE”,但精确匹配不起作用
match this title
match this title 002
但是当我运行相同的MYSQL查询在PHP中,我得到:(不正确)
match this title 002
我也试过对阵同样的结果与PHP和phpMyAdmin的:
$sql = "SELECT topic_title
FROM phpbb_topics
WHERE MATCH (topic_title)
AGAINST('match this title' IN BOOLEAN MODE)";
搜索使用的代码IM的整个街区:
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";
}
任何想法,以什么我做错了吗?
心中已经一直在寻找所有的地方和旁边没有帮助:(发现
啊是啊,只是在bash和php之间有点混淆,就像bash一样,你总是需要引号。但是这并不会损害引号的正确性吗?当我看到2个结果作为一个长句时,我还添加了
标签:P(干杯!) – Mint 2010-04-06 22:36:14
没有引号不会伤害。这是一个风格问题。我宁愿将所有变量都放在引号外面。 – 2010-04-07 07:54:55