Execute an SQL statement and return the first row.

@param string $sql
@param array  $parameters
@param bool   $indexedKeys
@return array|false
496499
public function fetchRow($sql, array $parameters = [], $indexedKeys = false)
    {
        $statement = $this->executeQuery($sql, $parameters);

        return $statement->fetch($indexedKeys ? PDO::FETCH_NUM : PDO::FETCH_ASSOC);
    }
189939
public function execute(string $sql, $bind = []): Statement
    {
        $this->operation = 'execute';
        $this->sql = $sql;
        $this->params = $bind;
        return $this;
    }
595507
private function _exec($sql, $arguments = array())
    {
        $sql = $this->replaceArgs($sql, $arguments);

        // executes the statement
        $result = $this->_conn->query($sql);
        if ($this->_conn->errno > 0) {
            throw new DbException(
                "Failed to execute the statement: " .
                "({$this->_conn->errno}) {$this->_conn->error}"
            );
        }

        return $result;
    }
1193708
protected function execute($sql, array $data = array())
    {
        try{
            foreach ($data as $key => $value) {
                $sql = str_replace(":".$key, "'".$value."'", $sql);
            }

            $execute = mssql_query($sql,$this->raw);

        }catch(\Exception $e){
            return null;
        }
        

        return $execute;
    }
368113
public static int[] executeBatch(Connection conn, String... sqls) throws SQLException {
		return executeBatch(conn, new ArrayIter<String>(sqls));
	}
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;
	}
217497
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->connection()->sqlExecute($sql, $params);
    }
226221
public function query(string $sql, array $params = []) {
        X::logger()->trace("$sql with params " . $this->serializeArray($params));
        try {
            $st = $this->pdo->prepare($sql);
            if ($st === false) {
                $e = $this->pdo->errorInfo();
                throw new DataBaseException($e[2], $e[1]);
            }
            if ($st->execute($params)) {
                $this->_affectedRows = $st->rowCount();
                $this->_lastInsertId = $this->pdo->lastInsertId();
                return $st->fetchAll(PDO::FETCH_ASSOC);
            }

            $e = $st->errorInfo();
            throw new DataBaseException($e[2], $e[1]);
        } catch (PDOException $ex) {
            X::logger()->trace($ex);
            throw new DataBaseException($ex->getMessage(), $ex->getCode());
        }
    }
1171730
public function run($sql, array $params = array())
    {
        $sth = $this->pdo->prepare($sql);

        foreach ($params as $key => $value) {
            $key = is_numeric($key) ? $key + 1 : ":$key";
            $sth->bindValue($key, $value);
        }

        $sth->execute($params);
        $this->executed[] = $sql;
        return $sth;
    }
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;
    }
1277492
public function execute($sql, array $params=array())
	{
		if ($params) {
			$stmt = $this->prepare($sql);
			if (!$stmt) { return false; }

			$flag = $stmt->execute($params);
			if (!$flag) { return false; }
		} else {
			$stmt = $this->query($sql);
			if (!$stmt) { return false; }
		}

		return $stmt->rowCount();
	}
678439
protected function cacheGet(string $sql, array $values = null, string $index = null){

		if($this->cache instanceof CacheInterface){
			return $this->cache->get($this->cacheKey($sql, $values, $index));
		}

		return false; // @codeCoverageIgnore
	}
860553
public static function execute($sql, $data = [])
    {
        $statement = self::$pdo->prepare($sql);
        $statement->execute($data);
        return $statement;
    }
1129620
public function query(string $sql, array $params = []): Statement
    {
        if (!$stmt = sqlsrv_query($this->connection, $sql, $params)) {
            throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params);
        }

        $statement = new Statement($stmt, false, $sql, $params);
        $statement->execute();
        return $statement;
    }
414290
public function getArray($sql = null, $parameters = array()) {
		$this->execute($sql, $parameters);
		return $this->result->fetchAll(\PDO::FETCH_ASSOC);
	}
267341
protected function execute($sql, array $data = array())
    {
        $statement = $this->raw->prepare($sql);

        return $statement->execute($data);
    }
343621
public static function getSqlWithParams(string $sql, array $params = []): string
    {
        if (! empty($params)) {
            $indexed = ($params === array_values($params));
            foreach ($params as $k => $v) {
                if (is_string($v)) {
                    $v = "'${v}'";
                }
                if (is_array($v)) {
                    $v = "'" . implode("','", $v) . "'";
                }
                if ($indexed) {
                    $sql = preg_replace('/\?/', $v, $sql, 1);
                } else {
                    $sql = str_replace(":${k}", $v, $sql);
                }
            }
        }

        return str_replace(PHP_EOL, '', $sql);
    }