【发布时间】:2011-04-03 02:28:43
【问题描述】:
我有一个从数据库中获取用户名和用户 ID 的 pdo 函数。当我运行该功能时,我会得到不同的结果。
print_r 给出
数组([ID] => 58 [用户名] => abdullatif)
foreach 给了我
5-5a-a
数据库中有一行与 pdo 查询匹配。
public function getUserCredentials($userName, $password){
$this->db = new Dbpdo_Database();
$this->db->connect();
try{
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT
ID
FROM
administrators
WHERE
username = :username
AND
user_password = :password
LIMIT 1");
$stmt->bindParam(':username', $userName, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
}
$stmt->execute();
/*** fetch the results ***/
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results;
/*** close the database connection ***/
//$dbh = null;
}
catch(PDOException $e){
echo $e->getMessage();
}
}
$results = $mydb->getUserCredentials($userName, $password);
foreach ($results as $row){
echo $row['ID'].'-'.$row['username'];
}
print_r($results);
任何关于什么错误的提示将不胜感激。提前致谢。
【问题讨论】: