Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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_Php_Mysql_Mysqli_Binding - Fatal编程技术网

在查询中使用匹配绑定字符串php mysql

在查询中使用匹配绑定字符串php mysql,php,mysql,mysqli,binding,Php,Mysql,Mysqli,Binding,当我使用这样的查询时,使用mysqli将PHP-MYSQL绑定到prepare语句可以正常工作 if ($stmt = $dbh->prepare("SELECT url, title, fulltxt FROM links WHERE id = ? ")){// do something} 但是当我使用这个查询时,它不起作用 if ($stmt = $dbh->prepare("SELECT url, title, fulltxt FROM links WHERE MATCH(f

当我使用这样的查询时,使用mysqli将PHP-MYSQL绑定到prepare语句可以正常工作

if ($stmt = $dbh->prepare("SELECT url, title, fulltxt FROM links WHERE id = ? ")){// do something}
但是当我使用这个查询时,它不起作用

if ($stmt = $dbh->prepare("SELECT url, title, fulltxt FROM links WHERE MATCH(fulltxt)  AGAINST(?) ")) {//do something}

我是个经验不足的程序员。因此,任何人都可以告诉我在查询绑定值时使用带问号的“MATCH()对()”的正确方法。

基于pastebin的新完整代码:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
    </head>
    <body>

        <?php
            error_reporting(-1);
            // here the db details

            $query = "%".$_GET['q']."%";

            // Connecting to the server and selecting database
            $dbh  = new mysqli($host, $user, $password,  $database);

            if ($dbh->connect_error) {
                echo 'Unable to connect to database '. $dbh->connect_error;
            } else {
                // run query to select records
                if ($stmt = $dbh->prepare("SELECT url, title, fulltxt FROM links WHERE fulltxt LIKE ?")) {
                    // binding user-supplier input $class to the parameter as string
                    $stmt->bind_param("s", $query);
                    // executing the statement
                    $stmt->execute();
                    // binding the table columns Name and Email to the $Name and Email parameters respectively.
                    $stmt->bind_result($URL, $TITLE, $FULLTXT);
                    /* fetch associative array */
                    while ($stmt->fetch()) {
                        echo $URL. ' -- '. $TITLE. '<br />';
                    }
                } else {
                       echo "Prepare failed: (" . $dbh->errno . ") " . $dbh->error;
                }
            }
        ?>

    </body>
</html>


通过用LIKE替换MATCH并在两侧用百分比字符连接变量,问题得到了解决。

看起来正确,会发生什么,错误?如果以静态方式传递值,它是否工作?它不会给出错误。(我没有关闭给出错误)你打开错误报告了吗?您是否准备了失败的
或只是没有返回结果?在DB上执行查询是否可以直接工作?否则{echo“准备失败:(“$stmt->errno.””)“$stmt->error;}我使用了此代码,但没有返回任何错误。您必须使用$dbh而不是$stmt!您是否也打开了错误报告功能?通过添加错误报告(-1);在php代码的开头?请检查我的完整代码。给你。我不知道为什么在添加else之后,{echo$dbh->error;}它给出了这个错误“PHP解析错误:语法错误,在…中意外的'else'(t_else)”,粘贴库中的代码仍然显示$stmt->error。这是不正确的,我认为这是正确的解决方案。但我不在主持我的节目。删除错误报告后(-1);不给钱。错误。谢谢你的尝试。我将在另一台服务器上试用该代码。可能是有一些问题,在目前的托管