Exemple #1
0
 /**
  * bind array of values
  *
  * example: where field in (:list)
  *
  * @param string $bind
  * @param array $array
  */
 protected function bindArray($bind, $array)
 {
     if (empty($array)) {
         return;
     }
     if (count($array) === 1) {
         $this->bindValue($bind, current($array));
         return;
     }
     // create array of bind variables for each entry in $array
     $binds = array();
     foreach ($array as $key => $val) {
         $binds[$bind . $key] = $val;
     }
     // create new sql where we replace the one bind variable with the list of bind variables
     $sql = str_replace($bind, implode(', ', array_keys($binds)), $this->statement->getSql());
     $this->statement->setSql($sql);
     // don't forget to re-bind previously bound variables
     $binds = array_merge($binds, $this->bindVariables);
     // bind all the new bind variables
     $this->bind($binds);
 }