Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php mysql中对()使用MATCH()时出错_Php_Mysql_Search - Fatal编程技术网

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

在php mysql中对()使用MATCH()时出错,php,mysql,search,Php,Mysql,Search,我是php新手。我正在尝试使用MATCH-on而不是LIKE搜索mysql-dayabase。使用这个脚本 <?php if (isset($_GET['q'])){ error_reporting(-1); $query = $_GET['q']; $dbh = new mysqli($host, $user, $password, $database); if ($dbh->connect_e

我是php新手。我正在尝试使用MATCH-on而不是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>';
}
    ?>
这个脚本中的问题在哪里

我想搜索匹配的数据库表

但同样的脚本也可以很好地使用

选择sura,aya,bn_孟加拉文中的文字,文字在哪里

为什么不配合工作呢? 这个脚本的问题在哪里?

索引在mysql中,它必须在backtick中

你的问题是

SELECT `index`, `sura`, `aya`, `text`...
索引
在mysql中,必须在backtick中

尝试将查询更改为:

SELECT `index`, `sura`, `aya`, `text` FROM...

此外,我建议您更改列名,以便将来也不会遇到问题,因为在进行此更改后,可能会出现错误。

最好在查询中的每一列中添加“backtick”。所以,如果您使用mysql保留关键字,那么它不会产生任何问题。试试下面的代码

  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>';
}
    ?>
if($dbh->connect\u错误){
echo“无法连接到数据库”。$dbh->connect\u错误;
}否则{
如果($stmt=$dbh->prepare($index`、`sura`、`aya`、`text`FROM bn_孟加拉文,其中匹配(sura,text)与(?))
{
$stmt->bind_参数(“s”,$query);
$stmt->execute();
$stmt->bind_result($index、$sura、$aya、$text);
$stmt->store_result();
printf(“行数:%d.\n”,$stmt->num\u行);
而($stmt->fetch()){
echo$sura.'-'.$aya;
echo$文本;
回声“
”; } }否则{ echo“准备失败:(“$dbh->errno.”“$dbh->error; } } }//end isset get q 其他的 { 回声“搜索”; } ?>
索引是MySQL中的保留字更改后选择SELECT
Index
sura
aya
text
其给出此错误准备失败:(1191)找不到与列列表匹配的全文索引请参考您的错误我已经在longtext中有文本。但在运行这个altertable bn_孟加拉文后,添加全文(text);错误仍然存在,因此查询
ALTER TABLE bn_bengali ADD FULLTEXT(
text
更改表格bn_孟加拉文添加全文(
sura
,并在更改后选中SELECT
index
sura
aya
text
其给出此错误准备失败:(1191)找不到与列匹配的全文索引list@HasanBinKarim,请尝试使用
ALTER
query更改列名。我将名称索引更改为id,但错误准备失败:(1191)找不到与列列表匹配的全文索引仍然存在。您是否也将查询@HasanBinKarim更改为
选择
id
sura
aya
text`FROM`
  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>';
}
    ?>