db query

@param string $sql
@return mixed
8118
public function query($sql)
    {
        if (true == Config::get('sql_log')) {
            wlog('SQL-Log', $sql);
        }

        $_key = strtolower(substr($sql, 0, 6));
        if ($_key == 'select') {
            $qt = 'query';
        } else {
            $qt = 'exec';
        }

        if (true == ($rs = $this->db->$qt($sql))) {
            $GLOBALS['__$DB_QUERY_COUNT']++;
            return $rs;
        } else {
            \show_error('DB_ERROR: ' . $this->db->lastErrorMsg() . "\nRAW_SQL: " . $sql);
        }
        //return false;
    }
930668
public function query($sql)
    {
        try {
            $result = $this->getConnect()->query($sql);
        } catch (mysqli_sql_exception $exception) {
            $reflect = new ReflectionClass($exception);
            $property = $reflect->getProperty('sqlstate');
            $property->setAccessible(true);
            throw (new Exceptions\QueryException($exception->getMessage(), $property->getValue($exception)))
                ->setQuery($sql);
        }

        return $result;
    }
897863
public function query($sql){
		LogMaster::log($sql);
		if ($this->start_from)
			$res = sqlsrv_query($this->connection,$sql, array(), array("Scrollable" => SQLSRV_CURSOR_STATIC));
		else
			$res = sqlsrv_query($this->connection,$sql);
		
		if ($res === false){
			$errors = sqlsrv_errors();
			$message = Array();
			foreach($errors as $error)
				$message[]=$error["SQLSTATE"].$error["code"].$error["message"];
			throw new Exception("SQLSrv operation failed\n".implode("\n\n", $message));
		}
		
		if ($this->insert_operation){
			sqlsrv_next_result($res);
			$last = sqlsrv_fetch_array($res);
			$this->last_id = $last["dhx_id"];
			sqlsrv_free_stmt($res);
		}
		if ($this->start_from)
			$data = sqlsrv_fetch($res, SQLSRV_SCROLL_ABSOLUTE, $this->start_from-1);
		return $res;
	}
1221076
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if ($row = mysqli_fetch_assoc($res))
		{
			$val = array_pop($row);
		}
		else
		{
			$val = false;
		}
		((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		return $val;
	}
884659
protected function execute($sql)
    {
        $this->lastQuery = $sql;

        $this->debugLog(sprintf('Executing SQL: %s', $sql));

        $this->sqlStatement = $this->getConnection()->prepare($sql, []);
        $this->sqlStatement->execute();
        $this->lastId = $this->connection->lastInsertId(sprintf('%s_id_seq', $this->getEntity()));

        // If their is an id, save it!
        if ($this->lastId) {
            $this->handleLastId($this->getEntity(), $this->lastId);
        }

        return $this->sqlStatement;
    }
1096221
public function query($sql) {
        $result = $this->executeRaw($sql);
        return new PostgresResult($this, $sql, $result, $this->lastAffectedRows());
    }
1302558
public function fetch_objects($sql)
    {
        $data = [];
        $result = $this->fetch_arrays($sql);
        foreach ($result as $v) {
            $data[] = (object)$v;
        }

        return $data;
    }
370381
public function getFirst($sql = null)
    {
        if ($sql) {
            $this->setLastQuery($sql);

            try {
                $result = $this->db->query($sql);
            } catch (\PDOException $e) {
                throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);
            }

            $data = $this->fetchAssoc($result);

            if (isset($data[0])) {
                return $data[0];
            }

            return null;
        }

        return $this->limit(1)->query()->fetchAssoc();
    }
996562
public function query(string $sql, $data = null) {
		$connection = $this->pool->getConnection();
		$result = null;
		$tryAgain = true;
SQL_START_EXECUTE:
		if (is_array($data) && count($data) > 0) {
			if (strpos($sql, ':') !== false) {
				$bind = [];
				$sql = preg_replace_callback('/:(\w+)\b/', function ($matches) use (&$data, &$bind) {
					$bind[] = $data[$matches[1]];
					return '?';
				}, $sql);
				$data = &$bind;
			}
			try {
				$st = $connection->prepare($sql);
				if ($st === false) {
					goto SQL_TRY_AGAIN;
				}
				if (is_object($st)) {
					$result = $st->execute($data);
				} else {
					$result = $connection->execute($data);
				}
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		} else {
			try {
				$result = $connection->query($sql);
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		}
SQL_TRY_AGAIN:
		if (($connection->errno === 2006 || $connection->errno === 2013) && $tryAgain) {
			$tryAgain = false;
			$connection = $this->pool->reconnect($connection);
			goto SQL_START_EXECUTE;
		} else {
			$error = $connection->error;
			$errno = $connection->errno;
			$this->pool->freeConnection($connection);
			throw new DBException($error, $errno);
		}
SQL_SUCCESS_RETURN:
		if ($result === true) {
			$result = [
				'_affected_rows' => $connection->affected_rows
			];
			if (stripos($sql, 'insert') === 0) {
				$result['_insert_id'] = $connection->insert_id;
			}
		}
		$this->pool->freeConnection($connection);
		return $result;
	}
1254602
protected function getStatement($sql)
    {
        if (!isset($this->statements[$sql])) {
            $this->statements[$sql] = $this->adapter->prepare($sql);
        }
        return $this->statements[$sql];
    }
62491
public function query($sql)
    {
        $sql = trim($sql);
        if (empty($sql)) {
            $callers = debug_backtrace();
            $msg = "Sorry I don't understand your SQL: " . PHP_EOL . $sql . PHP_EOL . PHP_EOL;
            $msg.= "I have been called by {$callers[1]['class']}::{$callers[1]['function']}";
            throw new \InvalidArgumentException($msg);
        }

        $data = array();
        $this->log->debug($this->logPrefix . 'Query: ' . preg_replace('/\s+/', ' ', $sql));

        $res = $this->sugarDb->query($sql, false);
        // Error in Query
        if (!empty($this->sugarDb->database->error)) {
            throw new \InvalidArgumentException("SQL Error in query: {$this->sugarDb->database->error}");
        }

        // No data to send to the caller
        if (!isset($res->num_rows)) {
            return true;
        }

        // Empty result
        if ($res->num_rows === 0) {
            return array();
        }

        // data to send
        while ($row = $res->fetch_assoc()) {
            $data[] = $row;
        }
        $res->free();

        return $data;
    }
1176928
public function query($sql, $bind = array())
    {
        // connect to the database if needed
        $this->_connect();

        // is the $sql a Zend_Db_Select object?
        if ($sql instanceof Zend_Db_Select) {
            if (empty($bind)) {
                $bind = $sql->getBind();
            }

            $sql = $sql->assemble();
        }

        // make sure $bind to an array;
        // don't use (array) typecasting because
        // because $bind may be a Zend_Db_Expr object
        if (!is_array($bind)) {
            $bind = array($bind);
        }

        // prepare and execute the statement with profiling
        $stmt = $this->prepare($sql);
        $stmt->execute($bind);

        // return the results embedded in the prepared statement object
        $stmt->setFetchMode($this->_fetchMode);
        return $stmt;
    }
1361597
public function sqlq($sql) {
    // $args = ['--db-prefix', '"' . $sql . '"'];
    $sql = strtr($sql, [
      "{" => '',
       "}" => ''
     ]);
    $output = trim($this->__call('sqlq', ['"' . $sql . '"']));
    $output = $this->cleanOutput($output);
    return $output;
  }
1029871
private function _parseSql($sql)
    {
        return array_values(array_filter(array_map(function ($value) { return trim(rtrim($value, $this->separator)); },
            preg_split(sprintf("/%s[\s]*\n/", preg_quote($this->separator)), rtrim(trim($sql), $this->separator)))));
    }
500695
public function fetch_arrays($sql)
    {
        $result = $this->db->query($sql);
        $array  = null;
        while (true == ($row = $result->fetchArray(SQLITE3_ASSOC))) {
            $array[] = $row;
        }
        $GLOBALS['__$DB_QUERY_COUNT']++;

        $result->finalize();
        return $array;
    }
354820
function buildQuery( $sql = NULL ) {
		if( !isset( $this->query ) OR empty( $sql ) ) {
			return FALSE;
		}

		$this->query .= $sql;

		return $this->query;
	}
47290
public function fetch_object($sql)
    {
        $rs   = $this->query($sql);
        $data = mysql_fetch_object($rs);

        mysql_free_result($rs);
        return $data;
    }