Пример #1
0
 public function one()
 {
     $quotedFields = array_map(function ($field) {
         return $this->db->quoteIdentifier($field);
     }, array_keys($this->fields));
     $placeholders = array_map(function ($field) {
         return '?';
     }, array_values($this->fields));
     $fieldsSql = join(', ', $quotedFields);
     $placeholdersSql = join(', ', $placeholders);
     $sql = 'INSERT INTO ' . $this->db->quoteIdentifier($this->table->getTableName()) . ' (' . $fieldsSql . ') VALUES (' . $placeholdersSql . ')';
     if ($this->db instanceof AdapterPgsqlConnection) {
         $row = $this->table->sqlOne($sql . ' RETURNING *', array_values($this->fields));
     } elseif ($this->db instanceof AdapterMysqliConnection) {
         $this->db->execute($sql, array_values($this->fields));
         $row = $this->table->id($this->db->lastInsertId());
     } else {
         throw new \Exception('Unreacheable statement');
     }
     return $row;
 }
Пример #2
0
 public function delete($where = '', array $args = [])
 {
     $whereSql = $where == '' ? '' : " WHERE {$where}";
     $this->db->execute('DELETE FROM ' . $this->quoteIdentifier(static::getTableName()) . $whereSql, $args);
     return $this->db->affectedRows();
 }
Пример #3
0
 public function affected()
 {
     list($sql, $args) = $this->prepareSqlAndArgs();
     $this->db->execute($sql, $args);
     return $this->db->affectedRows();
 }