开发者

pass PDO bindParam type in array

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


Sorry, self::fail()

Parameters being passed to the function didn't match the target tables - still, method works a treat!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜