【发布时间】:2016-04-25 06:02:05
【问题描述】:
我是 php 新手。我正在尝试使用 MATCH AGAINST 而不是使用 LIKE 来搜索 mysql dayabase。使用这个脚本,
<?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中的保留字