在数组中传递 PDO bindParam 类型
我试图将参数约束从数组传递给 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();
}
}
但是,它似乎令人窒息 - 如果我将常量传递给它,该函数将接收整数,并且它不会接受字符串描述
I am trying to pass the parameter constraint to PDO from an array i.e.
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();
}
}
However, it seems to choke - if I pass it the constant, the function recieves integers, and it won't accept a string description
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉, self::fail()
传递给函数的参数与目标表不匹配 - 尽管如此,该方法仍然有效!
Sorry, self::fail()
Parameters being passed to the function didn't match the target tables - still, method works a treat!