/** * Select request * @param bool $many * @param array|string $_key * @param array $where * @param string $type * @param string $beforeFrom * @param string $beforeWhere * @param string $afterWhere * @return array|mixed */ private function select($many, $_key, $where = [], $type = 'AND', $beforeFrom = '', $beforeWhere = '', $afterWhere = '') { $sqlData = []; $key = DfSql::prepareKeys($_key); $sql = "SELECT {$key} {$beforeFrom} FROM {$this->table} {$beforeWhere}"; if (!empty($where)) { $whereData = implode(" {$type} ", DfSql::makePlaceholders($where, false)['array']); $sqlData = DfSql::makePlaceholders($where, false)['data']; $sql .= " WHERE {$whereData}"; } $sql .= (!empty($where) ? ' ' : ' WHERE ') . $afterWhere; return $many === true ? $this->db->getRecordsByQuery($sql, $sqlData) : $this->db->getRecordByQuery($sql, $sqlData); }
/** * @param DfDbConnection $db */ public function check($db) { $this->assertEquals(['id' => 1, 'username' => 'test', 'email' => '*****@*****.**'], $db->getRecordByQuery("SELECT * FROM users WHERE id = :id", [':id' => 1])); $this->assertEquals([['id' => 1, 'username' => 'test', 'email' => '*****@*****.**']], $db->getRecordsByQuery("SELECT * FROM users WHERE id = :id", [':id' => 1])); }