Esempio n. 1
0
 /**
  * Update one or multiple rows in a table
  *
  * $helper->update('cars', ['model' => 'v70'], ['make' => 'volvo']);
  *
  * @param string $table
  * @param string[] $values
  * @param string[] $predicate columns used to build the where-part of the query
  * @return mixed
  */
 public function update($table, array $values, array $predicate = [])
 {
     $updateParts = [];
     $paramValues = [];
     $i = 0;
     foreach ($values as $key => $value) {
         $col = $this->quoteColumn($key);
         $paramName = ':qp' . $i;
         $updateParts[] = $col . ' = ' . $paramName;
         $paramValues[$paramName] = $value;
         $i++;
     }
     $table = $this->quoteColumn($table);
     $valueString = implode(',', $updateParts);
     $sql = "update {$table} set {$valueString} " . $this->buildPredicate($predicate, $paramValues);
     return $this->db->execute($sql, $paramValues);
 }