我构建了获取查询和参数并执行它的函数:
public static function doQuery($Query, $Params = array())
{
$psth = self::$dbh->prepare($Query);
foreach ($Params as $param => $value)
{
if (!is_numeric($value)){
echo "$value is not numeric \n";
$psth->bindParam($param, $value, \PDO::PARAM_STR);
}
else{
echo "$value is numeric \n";
$psth->bindParam($param, $value, \PDO::PARAM_INT);
}
}
$psth->execute();
return $psth;
}
当我运行此查询时:SELECT * FROM products WHERE Category = :CatId LIMIT 4
没有限制参数(CatId param很好)它的工作,
但是当我使用我的功能时这样:
$limit = 4;
$SParamsQuery = array(
":CatId" => $CatId,
":x" => 4
);
$SQuery = self::doQuery('SELECT * FROM products WHERE Category = :CatId LIMIT :x',$SParamsQuery);
这不起作用。
任何想法如何解决?
转储参数:
SQL: [58] SELECT * FROM `products` WHERE `Category` = :CatId LIMIT 4
Params: 1
Key: Name: [6] :CatId
paramno=-1
name=[6] ":CatId"
is_param=1
param_type=1
由于 海姆。
答案 0 :(得分:0)
如果你替换
,也许它会起作用$psth->bindParam($param, $value, \PDO::PARAM_INT);
与
$psth->bindParam($param, $value, PDO::PARAM_INT); //without backslash