Returns the first row of results from the statement

@param $statement
@param array $namedParameters
@param null $connection
@return string
425698
public static function returnFirstRow($statement, $namedParameters = [], $connection = null)
    {
        $statement = self::executeStatement(
            $statement,
            $namedParameters,
            $connection !== null ? $connection : static::getReadOnlyConnection()
        );

        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
494011
public function query($statement, $param1 = null, $param2 = null, $param3 = null)
    {
        if ($param3 !== null) {
            return parent::query($statement, $param1, $param2, $param3);
        }

        if ($param2 !== null) {
            return parent::query($statement, $param1, $param2);
        }

        if ($param1 !== null) {
            return parent::query($statement, $param1);
        }

        return parent::query($statement);
    }
1362423
public static function executeStatement(
        PDOStatement $statement,
        array $params = null
    ) {
        //Add the statement to the list of those run
        static::addStatement($statement);

        //Add bindings to the statement
        if (is_array($params)) {
            $statement->getBindings()
                ->hydrateFromArray($params);
        }

        $result = static::getOrCreateResultAt(static::numQueries());

        //Add the result to the statement
        $statement->setResult($result);

        //If a transaction is open, add the statement to it
        if (static::inTransaction()) {
            static::currentTransaction()->addStatement($statement);
        }

        //Increment number of queries run
        static::incrementNumQueries();

        if (static::shouldLogBacktrace()) {
            $statement->setBacktrace(
                static::makeBacktraceCollection(
                    debug_backtrace(
                        DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS,
                        static::resolveBacktraceLimit()
                    )
                )
            );
        }
    }
758537
public function prepare($statement) {
        $this->connect();

        $this->statement = new Statement($statement, $this->getParams(), $this->routings);
        $this->statement->setFetchMode($this->defaultFetchMode);

        return $this->statement;
    }
15961
public function exec($statement, $params = array())
    {
		
        if (count($params) > 0){
        	$sth = $this->dbConnector->prepare($statement);
        	$this->preparedExec = true;
        	$this->lastPreparedExecStatement = $sth;
        	$sth->execute($params);
        	$returnValue = $sth->rowCount();
        }
        else{
        	$this->preparedExec = false;
        	try {
        	    $returnValue = $this->dbConnector->exec($statement);
        	} catch (PDOException $e) {
        	    common_Logger::w('Error in statement: '.$statement);
        	    throw $e;
        	}
        }

        return (int) $returnValue;
    }
1071663
protected function readOne($query, $parameters)
    {
        $statement = $this->execute($query, $parameters);

        $rowCount = $statement->rowCount();
        if ($rowCount > 1) {
            throw new MultipleRowFoundException('Multiple row found for query: ' . $query);
        }

        if ($rowCount === 0) {
            throw new RowNotFoundException('Row not found for query: ' . $query);
        }

        return $statement;
    }
866045
public function executeStatement($statement, array $options = [])
    {
        if (!empty($options)) {
            return $this->session->execute($statement, $options);
        } else {
            return $this->session->execute($statement);
        }
    }
102098
public function prepare(string $statement) : PreparedStatementInterface
    {
        $preparedStatement = @$this->getConnection()->prepare($statement);

        if ($preparedStatement === false) {
            throw new ParserRuntimeException('Statement could not be prepared.', 0);
        }

        return new Sqlite3PreparedStatement($preparedStatement);
    }
869991
public function prepare($statement)
    {
        try {
            $stmt = new Statement($statement, $this);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
        }

        $stmt->setFetchMode($this->defaultFetchMode);

        return $stmt;
    }
979424
function getExecuteInsertSQL($statement) {

         $results = array();  //Array where all the sentences will be stored

         if ($sentences = $statement->getSentences()) {
             foreach ($sentences as $sentence) {
                 // Get the list of fields
                 $fields = $statement->getFieldsFromInsertSentence($sentence);
                 // Get the values of fields
                 $values = $statement->getValuesFromInsertSentence($sentence);
                 // Look if we have some CONCAT value and transform it dynamically
                 foreach($values as $key => $value) {
                     // Trim single quotes
                     $value = trim($value,"'");
                     if (stristr($value, 'CONCAT') !== false){
                         // Look for data between parenthesis
                         preg_match("/CONCAT\s*\((.*)\)$/is", trim($value), $matches);
                         if (isset($matches[1])) {
                             $part = $matches[1];
                             // Convert the comma separated string to an array
                             $arr = xmldb_object::comma2array($part);
                             if ($arr) {
                                 $value = $this->getConcatSQL($arr);
                             }
                         }
                     }
                     // Values to be sent to DB must be properly escaped
                     $value = $this->addslashes($value);
                     // Back trimmed quotes
                     $value = "'" . $value . "'";
                     // Back to the array
                     $values[$key] = $value;
                 }

                 // Iterate over fields, escaping them if necessary
                 foreach($fields as $key => $field) {
                     $fields[$key] = $this->getEncQuoted($field);
                 }
                 // Build the final SQL sentence and add it to the array of results
             $sql = 'INSERT INTO ' . $this->getEncQuoted($this->prefix . $statement->getTable()) .
                         '(' . implode(', ', $fields) . ') ' .
                         'VALUES (' . implode(', ', $values) . ')';
                 $results[] = $sql;
             }

         }
         return $results;
    }
320768
public static function bindToStatement(PDOStatement $statement, array $bindings=[])
    {
        foreach ($bindings as $key=>$value) {

            $casted = is_bool($value) ? (int)$value : $value;

            $statement->bindValue(
                is_string($key) ? $key : $key + 1,
                $casted,
                is_int($casted) ? PDO::PARAM_INT : ($casted === null ? PDO::PARAM_NULL : PDO::PARAM_STR)
            );

        }
    }
403758
public function fetchColumn(string $statement, array $bindings = [], int $columnNum = 0)
    {
        $sth = $this->execute($statement, $bindings);
        $result = $sth->fetchColumn($columnNum);

        $this->freeResource($sth);

        return $result;
    }
965917
public function q(string $statement, ...$params)
    {
        /**
         * @var array $result
         */
        $result = (array) $this->safeQuery(
            $statement,
            $params,
            self::DEFAULT_FETCH_STYLE,
            false,
            true
        );
        return $result;
    }
84760
public function findFirstVariableAssignment(array $statements, $name, $notFoundError = null)
    {
        foreach ($this->filterAssignments($statements) as $assign) {
            if ($assign->var instanceof Variable && $assign->var->name === $name) {
                return $assign;
            }
        }

        throw new \RuntimeException($notFoundError ?: sprintf('Variable assignment $%s not found', $name));
    }
759298
public function query($query_with_placeholders, $named_parameters = []) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_QUERY, '', $named_parameters, $query_with_placeholders), $named_parameters);
            try {
                $stmt = $this->prepareStatement($query_with_placeholders, $named_parameters);
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $query_with_placeholders, $named_parameters));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            Event::dispatch(EventData::forAfter(Event::AFTER_QUERY, null, $named_parameters, $query_with_placeholders, $stmt->rowCount()));

            return $this->fetch($stmt);
        }
642047
public static function Execute($statement, $parameters = array(), $return=false)
	{
		$db = self::connect();
		$rowsAffected = 0;
		$lastID = 0;
		
		try
		{
			$query = $db->prepare($statement);
			
			foreach($parameters as $key => $parameter)
			{
				if(!isset($parameter["type"]))
					$parameter["type"] = PDO::PARAM_STR;
				
				$query->bindParam($key,$parameter["value"],$parameter["type"]);
			}
			
			$db->beginTransaction();
			$query->execute();
			$rowsAffected += $query->rowCount();
			$lastID = $db->lastInsertId();
			$db->commit();
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$returnObject = (object) array(
			DatabaseReturn::RowsAffected => $rowsAffected,
			DatabaseReturn::LastInsertID => $lastID
		);
		
		if($return) return $returnObject;
		else return $rowsAffected;
	}
1071192
protected function bindParameters(\PDOStatement $statement, array $parameters, $prefix = '')
    {
        foreach ($parameters as $key => $value) {
            // In case of multiple rows are given for insert statement
            if (is_array($value)) {
                $statement = $this->bindParameters($statement, $value, $prefix . $key);
            } else {
                switch (true) {
                    case is_int($value):
                        $type = \PDO::PARAM_INT;
                        break;
                    case is_bool($value):
                        $type = \PDO::PARAM_BOOL;
                        break;
                    case $value === null:
                        $type = \PDO::PARAM_NULL;
                        break;
                    case $value instanceof \DateTimeInterface:
                        $type  = \PDO::PARAM_STR;
                        $value = $value->format('Y-m-d H:i:s.u');
                        break;
                    default:
                        $type = \PDO::PARAM_STR;
                }

                $statement->bindValue($prefix . $key, $value, $type);
            }
        }

        return $statement;
    }