我试图将参数约束从数组传递给PDO,即
public function write($sql,$bindparams=''){
try{
$stmt = $this->db_connection->prepare($sql);
if($bindparams != '' && is_array($bindparams)){
foreach($bindparams as $k){
$b = $k[0]; //parameter to bind to
$v = $k[1]; //the value
$c = $k[2]; //the parameter constraint(i.e. PDO::PARAM_STR)
$stmt->bindParam($b,$v,$c);
}
$stmt->execute();
}
}
catch(PDOException $e){
echo 'Error acquiring data: '.$e->getMessage();
exit();
}
}
然而,它似乎窒息 - 如果我传递常量,函数接收整数,它将不接受字符串描述
答案 0 :(得分:1)
抱歉,self :: fail()
传递给函数的参数与目标表不匹配 - 仍然,方法有效!