function apt_test() { $apt = new Swoole\SelectDB($this->db); $apt->from('users'); $apt->equal('id', 1); $res = $apt->getall(); var_dump($res); }
/** * 根据主键获取单条数据 * @param $id * @param $table * @param $primary * @return unknown_type */ public function get($id, $table, $primary = 'id') { $this->db_apt->init(); $this->db_apt->from($table); $this->db_apt->where("{$primary}='{$id}'"); return $this->db_apt->getone(); }
/** * 获取一个数据列表,功能类似于gets,此方法仅用于SiaoCMS,不作为同样类库的方法 * @param $params * @param $get * @return array */ function getList(&$params, $get = 'data') { $selectdb = new SelectDB($this->db); $selectdb->from($this->table); $selectdb->select($this->select); $selectdb->limit(isset($params['row']) ? $params['row'] : 10); unset($params['row']); $selectdb->order(isset($params['order']) ? $params['order'] : $this->primary . ' desc'); unset($params['order']); if (isset($params['typeid'])) { $selectdb->where($this->foreignkey . '=' . $params['typeid']); unset($params['typeid']); } $selectdb->put($params); if (array_key_exists('page', $params)) { $selectdb->paging(); global $php; $php->env['page'] = $params['page']; $php->env['start'] = 10 * intval($params['page'] / 10); if ($selectdb->pages > 10 and $params['page'] < $php->env['start']) { $php->env['more'] = 1; } $php->env['end'] = $selectdb->pages - $php->env['start']; $php->env['pages'] = $selectdb->pages; $php->env['pagesize'] = $selectdb->page_size; $php->env['num'] = $selectdb->num; } if ($get === 'data') { return $selectdb->getall(); } elseif ($get === 'sql') { return $selectdb->getsql(); } }