PDO的rowCount()
方法总是返回零值,即使有结果,根据:
count($sth->fetch(PDO::FETCH_ASSOC)) > 1
从这个PHP代码:
$_user = "a";
$_pass = "b";
$query = "select user,password from login where user = :user and password = :pass";
$conn = new PDO("sqlite:" .Config::$db_file);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$sth = $conn->prepare($query);
$sth->bindParam(':user', $_user);
$sth->bindParam(':pass', $_pass);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
echo "rowCount() = ",$sth->rowCount(),"\n";
echo 'count($result) = ', count($result), "\n";
print_r($result);
我明白了:
rowCount() = 0 count($result) = 2 Array ( [user] => a [password] => b )
如何解决这个问题?
答案 0 :(得分:3)