Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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 - Fatal编程技术网

绑定参数数组php mysql

绑定参数数组php mysql,php,mysql,Php,Mysql,我已经编写了一个与数组绑定的代码。 我现在的代码是: $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); $st

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

$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();
$user\u id=$\u会话['user\u id'];
$db=新的mysqli(“本地主机”、“用户名”、“密码”、“数据库”);
$stmt=$db->prepare(“从`scu_user-data`中选择AP,其中id=?限制1”);
$stmt->bind_参数('i',$user_id);
$stmt->execute();
$res=$stmt->get_result();
而($row=$res->fetch_数组(MYSQLI_ASSOC)){
如果($res[0]==0){
回声';
echo“window.location=”http://localhost/system/aps.php"';
回声';
}否则{
回声“;
}
}
$stmt->close();
我收到一条错误消息,上面说:

致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组


通过使用
MYSQLI_ASSOC
常量,您的代码的行为将与
MYSQLI_fetch_ASSOC()
相同,而
MYSQLI_NUM
将与
MYSQLI_fetch_row()
函数的行为相同,我认为这是您想要的

尝试使用

另外,在尝试从中提取行之前,请确保检查查询是否已成功运行,请更改
$res=$stmt->get_result()至:

if(!$res = $stmt->get_result()){
    die($db->error);
}
错误在这里:

if ($res[0] == 0)
$res是一个结果集对象。您可能想使用上一行中使用的变量$row:

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

可能查询没有成功运行?改进了格式。