gpt4 book ai didi

php - stmt 执行数组并获取

转载 作者:行者123 更新时间:2023-11-30 22:10:12 28 4
gpt4 key购买 nike

我正在尝试检查从 cookie 中检索到的 id 是否存在于数据库中,但是这部分代码

$stmt->bind_result($id, $uname); 

$username = $uname;

按照这个说 undefined variable 我应该没问题

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

在 zend 中给我一个警告错误。分配条件。如果 stmt->bind_result 对 mysqli 是正确的,我也不会 surch。

   /**
* Decode cookies and extract user ID
*/
$decryptCookieData = base64_decode($_COOKIE['rememberUserCookie']);
$user_id = explode("UaQteh5i4y3dntstemYODEC", $decryptCookieData);
$userID = $user_id[1];

/**
* check if id retrieved from the cookie exist in the database
* */
$db = dbconnect();
$stmt = $db->prepare('SELECT id, username FROM users WHERE id = ?');
$id = $userID;
$stmt->bind_param('i', $id);
$id = $userID;
$stmt->execute();

$stmt->store_result();
$stmt->bind_result($id, $uname);

if ($stmt->fetch()) {
$uid = $id;
$username = $uname;
/**
* Create the user session variable
*/
$_SESSION['id'] = $uid;
$_SESSION['username'] = $uname;
$isValid = true;

最佳答案

试试这个 $sth->fetch(PDO::FETCH_ASSOC); 并查看文档:http://php.net/manual/en/pdostatement.fetch.php

Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH).

因此,您可能会尝试从数字数组访问 $row['id']:

PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number Array ( [name] => banana [0] => banana [colour] => yellow [1] => yellow )

关于php - stmt 执行数组并获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40331584/

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