有人可以幫助我轉換成PDO這如何一些MySQL的轉換爲PDO
// verify email and password pair
$userid = 0;
$query = sprintf("SELECT id FROM users WHERE LOWER(email)='%s' AND passwordhash='%s'",strtolower($email),$pwdhash);
$resource = mysql_query($query);
if ($resource)
{
$row = mysql_fetch_row($resource);
if (isset($row[0]))
$userid = $row[0];
}
這是我的嘗試:
$userid = 0;
$resource = $dbh->query("SELECT id FROM users WHERE LOWER(email)=':email' AND passwordhash=':hash'");
$resource->bindValue(':email',$email,PDO::PARAM_STR);
$resource->bindValue(':hash',$pwdhash,PDO::PARAM_STR);
if ($resource->execute())
{
$result = array();
while ($row = $resource->fetch()) {
array_push($result, $row);
}
if (isset($result[0]))
$userid = $result[0];
$dbh = null;
return $result;
}
我敢肯定的東西是錯誤與內部的一部分,如果聲明
與其他嘗試:
$userid = 0;
$resource = $dbh->query("SELECT id FROM users WHERE LOWER(email)=':email' AND passwordhash=':hash'");
$resource->bindValue(':email',$email,PDO::PARAM_STR);
$resource->bindValue(':hash',$pwdhash,PDO::PARAM_STR);
if ($resource)
{
$row = $resource->fetchAll();
if (isset($row[0]))
$userid = $row[0];
}
// close database and return
$dbh = null;
return $userid;
}
有一些更多的嘗試......
$ dbh-> prepare而不是$ dbh->查詢我想。 – Szenis
用'prepare'替換'query'並刪除':email'和':hash'周圍的單引號 – Daan