您好我正在尝试使用带有php的pdo从数据库设置用户信息的缓存,但它会抛出一些错误
代码:
public function setUserCache($db)
{
if (!isset($_SESSION['user']['id']))
exit();
$statement = $db->prepare("SELECT * FROM users WHERE mail = :mail");
$statement->execute(array(':mail' => $_SESSION['user']['username']));
$userData = $statement->fetch(PDO::FETCH_ASSOC);
$statement = $db->prepare("SELECT * FROM data WHERE id = :id");
$statement->execute(array(':id' => $userData['id']));
$roleplayDate = $statement->fetch(PDO::FETCH_ASSOC);
while (list($var, $val) = each($userData)) {
$_SESSION['user'][$var] = $val;
}
while (list($var, $val) = each($roleplayDate[0])) {
$_SESSION['user'][$var] = $val;
}
}
错误:
E_WARNING Error in file »class.user.php« at line 101: Variable passed to each() is not an array or object
第101行:
while (list($var, $val) = each($roleplayDate[0])) {
循环时BOTH发生错误。