/** * Inits SQL query. * * @param string $queryType Type of the SQL query from types list from DBQuery. * @param array $conditions List of conditions for WHERE instruction. * @param array $fields List of fields for INSERT or UPDATE types of SQL queries. * * @return DBObject Oneself. * @throws DBCoreException If some error occurred. */ public function initQuery($queryType, $conditions = [], $fields = []) { $this->dbQuery = new DBPreparedQuery(); $this->dbQuery->setType($queryType); if (!is_array($conditions)) { throw new DBCoreException("Invalid conditions array"); } $this->dbQuery->conditions = $conditions; if (!is_array($fields)) { throw new DBCoreException("Invalid fields array"); } $this->dbQuery->fields = $fields; /* * Inits LIMIT if called dynamic select() or update() method. */ if (is_null($this->dbQuery->limit)) { $backTrace = debug_backtrace(); if (is_array($backTrace) && isset($backTrace[1])) { $prevCall = $backTrace[1]; if (is_array($prevCall) && isset($prevCall['type'])) { if ($prevCall['type'] == '->') { // dynamic method was called $this->dbQuery->limit = 1; } } } unset($backTrace); } return $this; }
/** * Inits SQL query. * * @param string $queryType Type of the SQL query from types list from DBQuery. * @param array $conditions List of conditions for WHERE instruction. * @param array $fields List of fields for INSERT or UPDATE types of SQL queries. * * @return DBObject Itself. */ public function initQuery($queryType, $conditions = array(), $fields = array()) { $this->dbQuery = new DBPreparedQuery(); $this->dbQuery->setType($queryType); $this->dbQuery->conditions = $conditions; $this->dbQuery->fields = $fields; /** * Inits LIMIT if called dynamic select() or update() method. */ if (is_null($this->dbQuery->limit)) { $backTrace = debug_backtrace(false, 2); if (!is_array($backTrace) && isset($backTrace[1])) { $prevCall = $backTrace[1]; if (is_array($prevCall) && isset($prevCall['type'])) { if ($prevCall['type'] == '->') { // called dynamic method $this->dbQuery->limit = 1; } } } unset($backTrace); } return $this; }