/** * @param $id * @param $db \Swoole\Database * @param $table * @param $primary * @param string $where * @param string $select */ function __construct($id, $db, $table, $primary, $where = '', $select = '*') { $this->db = $db; $this->_current_id = $id; $this->table = $table; $this->primary = $primary; if (empty($where)) { $where = $primary; } if (!empty($this->_current_id)) { $res = $this->db->query("select {$select} from {$this->table} where {$where} ='{$id}' limit 1")->fetch(); if (!empty($res)) { $this->_data = $res; $this->_current_id = $this->_data[$this->primary]; $this->_change = self::STATE_INSERT; } } }
/** * 删除当前条件下的记录 * @return bool */ function delete() { return $this->db->query("delete from {$this->table} {$this->where} {$this->limit}"); }
function __construct($id, $db, $table, $primary, $where = '', $select = '*') { $this->db = $db; $this->_current_id = $id; $this->table = $table; $this->primary = $primary; if (empty($where)) { $where = $primary; } if (!empty($this->_current_id)) { $res = $this->db->query("select {$select} from " . $this->table . ' where ' . $where . "='{$id}' limit 1"); $this->_data = $res->fetch(); $this->_current_id = $this->_data[$this->primary]; if (!empty($this->_data)) { $this->change = 1; } } }