我是php的新手.我试图使用MATCH AGAINST搜索mysql dayabase而不是使用LIKE.使用这个脚本,
<?php
if (isset($_GET['q'])){
error_reporting(-1);
$query = $_GET['q'];
$dbh = new mysqli($host, $user, $password, $database);
if ($dbh->connect_error) {
echo 'Unable to connect to database '. $dbh->connect_error;
} else {
if ($stmt = $dbh->prepare("SELECT index, sura, aya, text FROM bn_bengali WHERE MATCH(sura,text) AGAINST(?) "))
{
$stmt->bind_param("s", $query);
$stmt->execute();
$stmt->bind_result($index, $sura, $aya, $text);
$stmt->store_result();
printf("Number of rows: %d.\n", $stmt->num_rows);
while ($stmt->fetch()) {
echo $sura.'-'.$aya;
echo $text;
echo '<hr />';
}
} else {
echo "Prepare failed: (" . $dbh->errno . ") " . $dbh->error;
}
}
} // end isset get q
else
{
echo '<form action="" ><input type="text" name="q"><button>Search</button></form>';
}
?>
但它给出了这个错误,
Prepare failed: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index, sura, aya, text FROM bn_bengali WHERE MATCH(sura,text) AGAINST(?)' at line 1
这个脚本中的问题在哪里?
我想搜索匹配的数据库表.
但是同样的脚本工作正常
SELECT sura,aya,text FROM bn_bengali WHERE text LIKE?
为什么不匹配正在发挥作用?
这个脚本中的问题在哪里?
解决方法:
索引在mysql中是Reserved Words,它必须是反引号
你的查询是
SELECT `index`, `sura`, `aya`, `text`...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。