/** * Execute MySQL query * @param string $sql * @throws \DB\Exception\QueryError * @return resource|Result */ function query($sql, $timeout = self::QUERY_TIMEOUT, $is_retry = false) { $mysqli = $this->Connect(); //We are now in-query $this->isInQuery = $sql; //if(!\Server::isCLI()){ // set_time_limit($timeout); //} //Build SQL if applicable if ($sql instanceof IToSQL) { $sql = $sql->toSQL(); } //Do Query //echo $sql,"\r\n"; $res = $this->adapter->Query($sql); //Query Done $this->isInQuery = false; if ($res === false) { //Failure $errno = mysqli_errno($mysqli); if (!$is_retry && ($errno == 2006 || $errno == 2013 || $errno == 1213 && !$this->inTransaction())) { $this->reConnect(); return $this->Q($sql, $timeout, true); } $error = $this->Error(); file_put_contents('/tmp/last_sql.err', $sql); if (!$is_retry) { $this->call_filter('error_handler', $error); if ($error === null) { return $this->query($sql, $timeout, true); } } if ($this->inTransaction()) { if ($errno == 1205 || $errno == 1213 || $errno == 1689) { throw new TransactionException($error); } } throw new Exception\QueryError($sql, $error); } \Radical\DB::$query_log->addQuery($sql); //add query to log if ($res === true) { //Not a SELECT, SHOW, DESCRIBE or EXPLAIN return static::NOT_A_RESULT; } else { return new DBAL\Result($res, $this); } }