我有一个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; }
1 回答
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
就像上面的Nigel Ren所说,Quote:“在mysqli中,对bind_param()的调用是链接绑定变量的唯一方法,因此对execute()的调用实际上就是$ stmt-> execute();”。
- 1 回答
- 0 关注
- 158 浏览
添加回答
举报
0/150
提交
取消