尝试迁移到PDO无法弄清楚这个
有什么问题$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$sql = "SELECT COUNT(*) FROM users WHERE repo=? AND list=? AND email=?";
$q=$dbh->prepare($sql);
$res = $q->execute(array($repo, $list, $email));
$v = $res->fetchColumn();
答案 0 :(得分:1)
PDOStatement::execute()
返回TRUE
或FALSE
(请参阅here),因此$res
被设置为布尔值,然后您尝试调用一个方法就可以了。试试这个:
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$sql = "SELECT COUNT(*) FROM users WHERE repo=? AND list=? AND email=?";
$q=$dbh->prepare($sql);
if (($res = $q->execute(array($repo, $list, $email))) === FALSE) {
echo 'Query failed!';
exit;
}
$v = $q->fetchColumn();
答案 1 :(得分:0)
$q->execute(...)
仅返回布尔值。 正确的方法:
$q = $dbh->prepare($sql);
if ($q->execute($repo, $list, $email) == TRUE) {
$v = $q->fetchColumn();
} else {
//error
}