Attempts to explain a query

@param object $dbConnection
@param string $query
@param array  $parameters
@throws Exception
@return array
486802
protected function explainQuery($dbConnection, $query, $parameters = array())
    {
        $driver = $dbConnection->getAttribute(\PDO::ATTR_DRIVER_NAME);
        $query = $this->getExplainQuery($query, $driver);
        $statement = $dbConnection->prepare($query);
        if ($statement === false) {
            throw new Exception('Invalid query passed to explainQuery method');
        }
        $statement->execute($parameters);
        $result = $statement->fetch(\PDO::FETCH_ASSOC);
        if ($result === false) {
            throw new Exception('Query could not be explained with given parameters');
        }
        return $result;
    }
22342
public function execute( $query, $debug = 1 )
	{
		if( !$this->dbc )
			throw new RuntimeException( 'Database not conntected' );

		$result = FALSE;
		if( $query )
		{
			if( $debug > 0 )
			{
				$bits = $this->getBits( $debug, 5 );
				if( $bits[0] )
				{
					$this->countQueries++;
					$start = $this->getMicroTime();
				}
				if( $bits[1] )
					echo $query;
				if( $bits[2] )
					remark( $query );
				if( $bits[3] )
					die();
			}
			if( preg_match( '/^INSERT/i', ltrim( $query ) ) )
			{
				if( mysql_query( $query, $this->dbc ) )
				{
					$this->insertId = (int) mysql_insert_Id( $this->dbc );
					$result	= $this->insertId;
				}
			}
			else if( preg_match( '/^(SELECT|SHOW)/i', ltrim( $query ) ) )
			{
				$result = new DB_Result();
				if( $q = mysql_query( $query, $this->dbc ) )
				{
					while( $d = mysql_fetch_array( $q ) )
					{
						$row = new DB_Row();
						foreach( $d as $key => $value )
							$row->$key = $value;
						$result->rows[] = $row;
					}
				}
			}
			else
			{
				$result = mysql_query( $query, $this->dbc );
			}
			if( mysql_errno() )
				$this->handleError( mysql_errno(), mysql_error(), $query );
			if( $debug > 0 )
			{
				if( $bits[0] )
					$this->countTime += $this->getTimeDifference( $start );
				if( $bits[4] )
					die();
			}
			return $result;
		}
	}
834826
public function query($query) {
    if(method_exists($this->db, 'query')) {
      return $this->db->query($query);
    } else {
      throw new Exception(__METHOD__ . " not implemented");
    }
  }
574658
public static function bindExecuteLastInsertId($query, $parameters = [])
    {
        try {
            return static::$adapter->bindExecuteLastInsertId($query, $parameters);
        } catch (\Exception $e) {
            throw new DatabaseException('Database Error', $e->getMessage());
        }
    }
1300204
public function execute($query, $parameters = [])
    {
        $statement = $this->link->prepare($query);
        $statement->execute($parameters);
        return $statement->rowCount();
    }
157035
protected function checkForDatabaseError($query, $callingFunctionName)
    {
        $dbCon = $this->getDbConnection();
        if (is_a($dbCon, 'PDO') && ('00000' !== $dbCon->errorCode())) {
            $errorInfo = $dbCon->errorInfo();
            throw new Exception('PDO error code: ' . $dbCon->errorCode() . ' in function ' . $callingFunctionName . ' -- ' . $errorInfo[2] . ' -- ' . $query);
        }
    }
676434
public function exec($query)
    {
        if ($this->isConnected()) {
            try {
                return $this->pdo->exec($query);
            } catch (PDOException $e) {
                throw new \Exception($e->getMessage());
                return false;
            }
        } else {
            return false;
        }
    }
1107298
public function explainAction($token, $connectionName, $query)
    {
        /** @var Profiler $profiler */
        $profiler = $this->container->get('profiler');
        $profiler->disable();

        $profile = $profiler->loadProfile($token);
        $queries = $profile->getCollector('db')->getQueries();

        if (! isset($queries[$connectionName][$query])) {
            return new Response('This query does not exist.');
        }

        $query = $queries[$connectionName][$query];
        if (! $query['explainable']) {
            return new Response('This query cannot be explained.');
        }

        /** @var Connection $connection */
        $connection = $this->container->get('doctrine')->getConnection($connectionName);
        try {
            if ($connection->getDatabasePlatform() instanceof SQLServerPlatform) {
                $results = $this->explainSQLServerPlatform($connection, $query);
            } else {
                $results = $this->explainOtherPlatform($connection, $query);
            }
        } catch (Exception $e) {
            return new Response('This query cannot be explained.');
        }

        return new Response($this->container->get('twig')->render('@Doctrine/Collector/explain.html.twig', [
            'data' => $results,
            'query' => $query,
        ]));
    }
1267916
private function prepareStatement($query, $parameters) {
            $stmt = $this->db_connection->prepare($query);

            if (!empty($parameters)) {
                foreach ($parameters as $key => $val) {
                    $stmt->bindValue($key, $val);
                }
            }

            return $stmt;
        }
886803
public function query(
        Query $query,
        array $parameters = []
    ): Result {
        $this->load();

        return parent::query($query);
    }
1361195
public static function _genQuery ($params, &$db = FALSE)
	{
		
		// Set select

		if (!isset ($params['select']))
		{
			$params['select']	= '*';
		}
		
		// Set from

		if (!isset ($params['from']))
		{
			$params['from']		= '`' . static::$dbTable . '`';
		}
		
		// Get database slave for read

		if ($db === FALSE)
		{
			$db	=& self::_getDbSlave ();
		}
		
		if (!($db instanceof \PDO))
		{
			throw new Exception ('Invalid or no database resource set');
		}
		
		// Return value

		return $db->genQuery ($params);
		
	}
356196
public function bindExecute($query, $parameters = [])
    {
        $statement = $this->link->prepare($query);

        foreach ($parameters as $index => $paramProperties) {
            if (is_object($paramProperties)) {
                $paramProperties = (array) $paramProperties;
            }
            if (is_array($paramProperties)) {
                $statement->bindValue(
                    (int) $index + 1,
                    $paramProperties['value'],
                    $paramProperties['param']
                );
            } else {
                $statement->bindValue((int) $index + 1, $paramProperties);
            }
        }

        $statement->execute();

        return $statement->rowCount();
    }
498860
public static function query($sql) {
        self::init();
        try {
            $db = self::connect();
            if(is_array($db)) {
                throw new DbException('Connection error');
            }
            if(!$query = $db->query($sql)) {
                throw new DbException('Failed to execute query!');
            }
        } catch(mysqli_sql_exception $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);

        } catch(DbException $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);
        }
        if(isset($query) && isset($db)) {
            return ['result' => $query, 'link' => $db];
        }
    }
555910
public function gatherQueryData($dbConnection = null)
    {
        if (is_null($dbConnection)) {
            return array();
        }

        if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) {
            $this->setProfiledQueries($dbConnection->queries);
        }

        $data = array();
        foreach ($this->profiledQueries as $query) {
            array_push($data, array(
                'sql'     => $query['sql'],
                'explain' => $this->explainQuery($dbConnection, $query['sql'], $query['parameters']),
                'time'    => $query['time']
            ));
        }
        return $data;
    }
929214
protected function queryHandler($query, $bindings, $time, $connectionName)
    {
        $data = ['connectionName' => $connectionName];

        if ($this->recordSqlBindings) {
            $data['bindings'] = $bindings;
        }

        Integration::addBreadcrumb(new Breadcrumb(
            Breadcrumb::LEVEL_INFO,
            Breadcrumb::TYPE_USER,
            'sql.query',
            $query,
            $data
        ));
    }
391957
private function executeQuery(string $query, array $parameters) : bool
    {
        $statement = $this->pdo->prepare($query);
        $statement->execute($parameters);

        return $statement->rowCount() !== 0;
    }
702090
protected function pdoException(string $query, array $params) : void
    {
        $this->createException($this->pdo->errorInfo()[2], $query, $params);
    }