开发者

pass PDO bindParam type in array

开发者 https://www.devze.com 2022-12-18 12:16 出处:网络
I am trying to pass the parameter constraint to PDO from an array i.e. public function write($sql,$bindparams=\'\'){

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

精彩评论

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