Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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 prepared语句返回空值_Php_Mysql - Fatal编程技术网

Php MySQL prepared语句返回空值

Php MySQL prepared语句返回空值,php,mysql,Php,Mysql,我已经创建了一个MYSQL语句来查询我的数据库,但是我没有得到我想要的结果。var_dump返回一个空值。这是我的密码 使用完整代码和错误进行更新 不确定哪里出错。在执行语句后,我进行了另一个var_转储,它返回了以下错误objectmysqli_stmt2 0{}。这个错误意味着什么?我如何修复它?谢谢 您没有将值传递给它 $number = $_POST ['callerID']; $qry = "SELECT * FROM call_outcome WHERE cal

我已经创建了一个MYSQL语句来查询我的数据库,但是我没有得到我想要的结果。var_dump返回一个空值。这是我的密码

使用完整代码和错误进行更新

不确定哪里出错。在执行语句后,我进行了另一个var_转储,它返回了以下错误objectmysqli_stmt2 0{}。这个错误意味着什么?我如何修复它?谢谢


您没有将值传递给它

   $number = $_POST ['callerID'];
        $qry = "SELECT * FROM call_outcome WHERE callerid LIKE ? LIMIT 10";
        $stmt = mysqli_prepare ( $link, $qry );
        $stmt->bind_param('i', $number); 
        $stmt->execute ();
        $res = $stmt->fetch ();
我还没有和mysqli合作过,可能想再检查一下


请检查此更新代码:

        function dynamicsearch() {
    $link = mysqli_connect ( '192.168.2.113', 'root', '', 'solstats' );

    if (isset ( $_POST ['callerID'] )) {
        $number = $_POST ['callerID'];
        $qry = "SELECT * FROM call_outcome WHERE callerid LIKE '%?%' LIMIT 10";
        $stmt = mysqli_prepare ( $link, $qry );
        mysqli_stmt_bind_param($stmt, "s", $number); //for integer use i , for string use s
        mysqli_stmt_execute($stmt);
        $res= mysqli_stmt_fetch($stmt);       
        return $res;

    }
}

我只是尝试了一下,没有效果,两个错误仍然显示。检查现在刚刚更新,这是以前的PDO语法,很抱歉。有任何错误报告吗?SQL没有返回结果的原因肯定是没有传入参数。我认为execute和括号之间的空格可能会导致语法错误。也可以被称为RID是字符串吗?也许可以将其转换为$number=int$_POST['callerID'];您需要在bind_param函数中提到callerid字段的数据类型如果数据类型是string,您需要将其称为“s”,这是以前建议的,没有任何区别。我认为您混合了mysqliI的过程和面向对象方法,之前没有看到您的编辑,我只是尝试了一下,它没有加载任何东西,甚至没有var_dump错误。我使用的是PHP5.1,所以我认为您的一些语法不受支持。您必须在执行之前绑定参数。使用bind_param方法。更新了原始OP。请查看,因为我仍然有相同的错误。您好,谢谢您的建议。我刚刚尝试了这个页面没有加载任何内容。mysqli_stmt在PHP5.1中工作吗?没有。所有函数都随PHP5一起提供。请使用$number=%;而不是$number=$\u POST['callerID'];让我们。
        function dynamicsearch() {
    $link = mysqli_connect ( '192.168.2.113', 'root', '', 'solstats' );

    if (isset ( $_POST ['callerID'] )) {
        $number = $_POST ['callerID'];
        $qry = "SELECT * FROM call_outcome WHERE callerid LIKE '%?%' LIMIT 10";
        $stmt = mysqli_prepare ( $link, $qry );
        mysqli_stmt_bind_param($stmt, "s", $number); //for integer use i , for string use s
        mysqli_stmt_execute($stmt);
        $res= mysqli_stmt_fetch($stmt);       
        return $res;

    }
}
<?php
function dynamicsearch() {
    $link = mysqli_connect('192.168.2.113', 'root', '', 'solstats');
    $result = array();
    if (isset($_POST ['callerID'])) {
        $number = $_POST ['callerID'];
        $qry = "SELECT * FROM call_outcome WHERE callerid LIKE ? LIMIT 10";
        $stmt = mysqli_prepare($link, $qry);

        mysqli_stmt_bind_param($stmt, 's', $number);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $id, $callerid, $calldate, $ivron, $bopon, $type, $uniqueid, $queue_name);
        while (mysqli_stmt_fetch($stmt)) {
            $result[] = ['id' => $id, 'callerid' => $callerid, 'calldate' => $calldate, 'ivron' => $ivron,
                'bopon' => $bopon, 'type' => $type, 'uniqueid' => $uniqueid, 'queue_name' => $queue_name];
        }
    }
    return $result;
}
$IDdata = dynamicsearch();
?>
<!DOCTYPE html>
<html>
    <body>
        <h2>DB Query Results</h2>
        <table border="2">
            <tr>
                <th>id</th>
                <th>callerid</th>
                <th>calldate</th>
                <th>ivron</th>
                <th>bopon</th>
                <th>type</th>
                <th>uniqueid</th>
                <th>queue_name</th>
            </tr>
            <tr>        
                <?php
                foreach ($IDdata as $result) { // Fecth array used to fetch each array of the queried result and populate it to the table.
                    echo "<tr>";
                    echo "<td>" . $result ['id'] . "</td>";
                    echo "<td>" . $result ['callerid'] . "</td>";
                    echo "<td>" . $result ['calldate'] . "</td>";
                    echo "<td>" . $result ['ivron'] . "</td>";
                    echo "<td>" . $result ['bopon'] . "</td>";
                    echo "<td>" . $result ['type'] . "</td>";
                    echo "<td>" . $result ['uniqueid'] . "</td>";
                    echo "<td>" . $result ['queue_name'] . "</td>";
                    echo "</tr>";
                }
                ?>
            </tr>
        </table>
    </body>
</html>