gpt4 book ai didi

php - 绑定(bind)参数数组 php mysql

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

我已经编写了一个与数组绑定(bind)的代码。我现在的代码是:

$user_id = $_SESSION['user_id'];

$db = new mysqli("localhost", "username", "password", "database");

$stmt = $db -> prepare("SELECT aps FROM `scu_user-data` WHERE id=? LIMIT 1");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$res = $stmt->get_result();

while ($row = $res->fetch_array(MYSQLI_ASSOC)) {
if ($res[0] == 0){
echo '<script type="text/javascript">';
echo 'window.location = "http://localhost/system/aps.php"';
echo '</script>';
} else {
echo " ";
}
}

$stmt->close();

我收到一条错误消息:

Fatal error: Uncaught Error: Cannot use object of type mysqli_result as array

最佳答案

错误在这里:

if ($res[0] == 0)

$res 是结果集对象。大概您打算使用上一行中使用的变量 $row:

if ($row['aps'] == 0)

关于php - 绑定(bind)参数数组 php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54970750/

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