Example #1
0
 public function delete($data)
 {
     $data = $this->processData($data);
     $sql = new SQLBuilder($this->conn, $this->getFullyQualifiedTableName());
     $sql->delete($data);
     $values = $sql->bindValues();
     return $this->conn->query($this->last_sql = $sql->toString(), $values);
 }
Example #2
0
 /**
  * Updates records using set in $options
  *
  * Does not instantiate models and therefore does not invoke callbacks
  *
  * Update all using a hash:
  *
  * <code>
  * YourModel::updateAll(array('set' => array('name' => "Bob")));
  * </code>
  *
  * Update all using a string:
  *
  * <code>
  * YourModel::updateAll(array('set' => 'name = "Bob"'));
  * </code>
  *
  * An options array takes the following parameters:
  *
  * <ul>
  * <li><b>set:</b> String/hash of field names and their values to be updated with
  * <li><b>conditions:</b> Conditions using a string/hash/array</li>
  * <li><b>limit:</b> Limit number of records to update (MySQL & Sqlite only)</li>
  * <li><b>order:</b> A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)</li>
  * </ul>
  *
  * @params array $options
  * return integer Number of rows affected
  */
 public static function updateAll($options = [])
 {
     $table = static::table();
     $conn = static::connection();
     $sql = new SQLBuilder($conn, $table->getFullyQualifiedTableName());
     $sql->update($options['set']);
     if (isset($options['conditions']) && ($conditions = $options['conditions'])) {
         if (\is_array($conditions) && !isHash($conditions)) {
             \call_user_func_array([$sql, 'where'], $conditions);
         } else {
             $sql->where($conditions);
         }
     }
     if (isset($options['limit'])) {
         $sql->limit($options['limit']);
     }
     if (isset($options['order'])) {
         $sql->order($options['order']);
     }
     $values = $sql->bindValues();
     $ret = $conn->query($table->last_sql = $sql->toString(), $values);
     return $ret->rowCount();
 }