gpt4 book ai didi

php - MySQL 准备好的语句返回 NULL 值

转载 作者:行者123 更新时间:2023-11-29 22:48:29 25 4
gpt4 key购买 nike

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

更新完整代码和错误

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 );
$stmt->bind_param('s', $number);
$stmt->execute ();
var_dump($stmt);
$res = $stmt->fetch ();
$row = mysqli_fetch_assoc ( $res );
return $res;

}
}


var_dump ( $res );
$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
while ( $result = mysqli_fetch_array ( $IDdata ) ) { // 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>

不确定我哪里出错了。在执行该语句后我又做了一个var_dump,它返回了以下错误object(mysqli_stmt)#2 (0) { } .此错误是什么意思以及如何修复它?谢谢。

Error

最佳答案

您没有向其传递值。

   $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,可能想仔细检查一下。

http://php.net/manual/en/mysqli-stmt.bind-param.php

关于php - MySQL 准备好的语句返回 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28986115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com