SQL PDO使用3个参数计数行


SQL PDO count rows with 3 param

我有以下代码:

 public static function check($ip,$op,$page)
 {
$con = new PDO(DBN,DB_USER,DB_PASS);
$sql = "SELECT COUNT(*) FROM ips WHERE ip=:ip";
$st = $con->prepare($sql);
$st->bindValue(":ip",$ip,PDO::PARAM_STR);

$st->execute();
$counter = $st->fetchColumn();
 $con  = null;
 return $counter;
  }

$counter显示正确的行数,但如果我添加

       $st->bindValue(":op",$op,PDO::PARAM_INT);
       $st->bindValue(":page",$page,PDO::PARAM_INT);

$counter出现布尔值false;我仔细检查了我的数据库,但那里的一切都很好。我试着添加其中一个和另一个,但问题仍然存在;

您可以激活PDO调试并查看您的查询是否有问题:

$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);