我有一个pdo语句的片段,我想将其用作mysqli语句,但是我似乎并没有得到它的帮助。
我试图将mysqli-> execute(array())从pdo语句转换为mysqli语句。
据我了解,有execute()语句,它不希望使用mysqli参数,但使用PDO则需要一个参数?
这是代码,我想将其转换为mysqli语句:
$sql = "SELECT * FROM users WHERE username = :username";
$sth = $GLOBALS["DB"]->prepare($sql);
$sth->execute(array(":username" => $username));
$result = $sth->fetchAll();
if (!empty($result)) {
$privUser = new PrivilegedUser();
$privUser->user_id = $result[0]["user_id"];
$privUser->username = $username;
$privUser->password = $result[0]["password"];
$privUser->email_addr = $result[0]["email_addr"];
$privUser->initRoles();
return $privUser;
} else {
return false;
}
这是我当前的代码是:
$sql = "SELECT * FROM users WHERE user_id = ?";
$stmt = $mysqli -> prepare($sql);
$stmt->bind_param('s', $user_id);
// line below is what i need to convert to a mysqli statement
$stmt->execute(array(":user_id" => $user_id));
//$stmt->store_result();
$result = $stmt->fetchAll();
if (!empty($result)) {
$privUser = new PrivilegedUser();
$privUser->user_id = $result[0]["user_id"];
$privUser->username = $user_id;
$privUser->password = $result[0]["password"];
$privUser->email_addr = $result[0]["email_addr"];
$privUser->initRoles();
return $privUser;
} else {
return false;
}
慕尼黑的夜晚无繁华