doushuo2834 2016-04-25 06:02
浏览 64
已采纳

在php mysql中使用MATCH()AGAINST()时出错

I'm new in php. I am trying to search mysql dayabase using MATCH AGAINST rather than using LIKE. using this script,

    <?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.
", $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>';
}
    ?>

but it's giving this error,

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

Where is the problem in this Script?

I want to search the database table with match against.

But the same script is working fine with

SELECT sura, aya, text FROM bn_bengali WHERE text LIKE ?

why not match against is working? Where is the problem in this script?

  • 写回答

3条回答 默认 最新

  • drnmslpz42661 2016-04-25 06:05
    关注

    index is Reserved Words in mysql it must be in backtick

    Your query would be

    SELECT `index`, `sura`, `aya`, `text`...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?