我正在尝试将mysql脚本转换为mysqli并撞墙。我试图将mysql_result转换为mysqli然而我不确定如何做到这一点,下面是我的代码
$_SESSION['num_user'] = mysql_result(mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(*) FROM `members` WHERE mem_emailactivated = 1"), 0);
答案 0 :(得分:2)
虽然很奇怪,但似乎没有准备/执行的方法。
$stmt = mysqli_prepare($GLOBALS['___mysqli_ston'], "SELECT COUNT(*) AS count ...");
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $count);
mysqli_stmt_fetch($stmt);
$_SESSION['num_user'] = $count;
答案 1 :(得分:0)
你在这里混合了什么。您不会使用mysql_result
来使用mysqli
从查询中获取结果。您将使用mysqli
迭代返回的数组,然后将此数组存储在$_SESSION
中。
$result = $mysqli->query("call getUsers()");
if($result){
// Cycle through results
while ($row = $result->fetch_object()){
$user_arr[] = $row;
}
$result->close();
}
$_SESSION['num_user'] = $user_arr;
答案 2 :(得分:0)
使用SafeMysql:
$sql = "SELECT COUNT(*) FROM `members` WHERE mem_emailactivated = 1";
$_SESSION['num_user'] = $db->getOne($sql);