0

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

sunwukung
  • 2,815
  • 3
  • 41
  • 56
  • Hi I want to use this. How do I use this function? Will I just pass the sql statement with placeholders example `INSERT INTO table VALUES(:var1)` then second parameter `array(':var1'=>'var1value')` is this right? – Aivan Monceller Sep 29 '11 at 01:04
  • yup, that's right - the main thing is you have to put the :var placeholders in your sql string – sunwukung Sep 30 '11 at 13:57

1 Answers1

1

Sorry, self::fail()

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

sunwukung
  • 2,815
  • 3
  • 41
  • 56