Executes a query on the storage engine. Should be only used for INSERT,
DELETE statements.

@access public
@author Jerome Bogaerts, <jerome@taotesting.com>
@param  string statement
@param  array params
@return int
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;
    }
1254347
public function queryAssoc($statement, $params = array()) {
        $start = microtime(true);
        $query = $this->prepare($statement);
        try {
            $query->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $statement .'',
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $r = $query->fetchAll(\PDO::FETCH_ASSOC);
        $this->debug($statement . '', array(
            'params' => $params,
            'intoArray' => 'assoc',
            'rows' => count($r),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $r;
    }
1302544
public function queryClass($statement, $classname, $params = array(), $ctorargs = array()) {
        $start = microtime(true);
        $q = $statement . '';
        if (is_a($statement, ModelCondition::className())){
            foreach ($statement->getJoinParams() as $k=>$v){
                $params[$k] = $v;
            }
        }
        $statement = $this->prepare($q);
        try {
            $statement->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $q,
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $objects = array();
        while ($ob = $statement->fetchObject($classname, $ctorargs)) {
            $objects[] = $ob;
        }
        $this->debug($q, array(
            'params' => $params,
            'intoClass' => $classname,
            'controllerArguments' => $ctorargs,
            'rows' => count($objects),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $objects;
    }
1036747
protected function bindParameters(Statement $statement, array $parameters): Statement
    {
        foreach ($parameters as $index => $parameter) {
            if (is_numeric($index)) {
                //Numeric, @see http://php.net/manual/en/pdostatement.bindparam.php
                $statement->bindValue($index + 1, $parameter->getValue(), $parameter->getType());
            } else {
                //Named
                $statement->bindValue($index, $parameter->getValue(), $parameter->getType());
            }
        }

        return $statement;
    }
1047928
public int execute(String sql, Object... params) {
        Connection conn = getConn();
        try {
            return conn.createQuery(sql)
                    .withParams(params)
                    .executeUpdate()
                    .getResult();
        } finally {
            this.closeConn(conn);
            this.clean(conn);
        }
    }
1121894
public function execute($statement, array $bind = [])
    {
        $stmt = $this->query($statement, $bind);
        return $stmt->rowCount();
    }
247037
private function executeWrite($statement, array $parameters)
    {
        if ($this->transactionCount == 0) {
            $connection = $this->pool->selectWriteConnection();
        } else {
            $connection = $this->transactionConnection;
        }

        try {
            return $connection->execute(
                $this->expandPlaceholders($statement, $parameters),
                $parameters
            );
        } catch (ConnectionException $e) {
            $this->pool->disableWriteConnection($connection);
            if ($this->pool->getWriteConnectionCount() == 0) {
                throw $e;
            }

            return $this->executeWrite($statement, $parameters);
        }
    }
734477
public function exec(string $statement) : bool
    {
        try {
            return ($this->getConnection()->exec($statement) !== false);
        } catch (\PDOException $e) {
            throw new ParserRuntimeException('Statement could not be executed.', 0, $e);
        }
    }
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);
    }
273577
function delete( $table, $where = array(), $params = array() ) {

        if ( !is_array( $where ) ) $where = array( $where );
        if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 2 );

        $table = $this->rewriteTable( $table );
        $query = "DELETE FROM " . $this->quoteIdentifier( $table );
        $query .= $this->getSuffix( $where );

        $this->onQuery( $query, $params );

        $statement = $this->prepare( $query );
        $statement->execute( $params );

        return $statement;

    }
217497
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->connection()->sqlExecute($sql, $params);
    }
138225
public function statement( $query, $params = array() )
	{
		// we alway prepare the query even if we dont have parameters
		$sth = $this->driver()->connection()->prepare( $query );
		
		// because we set pdo the throw exception on db errors
		// we catch them here to throw our own exception.
		try 
		{
			$sth->execute( $params );
		}
		catch ( \PDOException $e ) 
		{
			throw new Exception( "DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}" );
		}
		
		// In development we alway log the query into an array.
		if ( \ClanCats::in_development() ) 
		{	
			$keys = array();
			
			foreach ( $params as $key => $value ) 
			{
				if ( is_string( $key ) ) 
				{
					$keys[] = '/:'.$key.'/';
				} else {
					$keys[] = '/[?]/';
				}
			}
			
			static::$_query_log[] = preg_replace( $keys, $params, $query, 1 );
		}
		
		return $sth;
	}
657974
public function execute($params = null)
    {
        $stmt = null;
        $attempt = 0;
        $retry = true;
        while ($retry) {
            $retry = false;
            try {
                $stmt = $this->stmt->execute($params);
            } catch (\Exception $e) {
                if ($this->conn->canTryAgain($attempt) && $this->conn->isRetryableException($e, $this->sql)) {
                    $this->conn->close();
                    $this->createStatement();
                    ++$attempt;
                    $retry = true;
                } else {
                    throw $e;
                }
            }
        }

        return $stmt;
    }
184426
public function exists(string $statement, ...$params): bool
    {
        /**
         * @var string|int|float|bool|null $result
         */
        $result = $this->single($statement, $params);
        return !empty($result);
    }
39325
public void execute(String query, Object... params) throws SQLException {
        createPreparedStatement(query, 0, params).execute();
    }
814002
function getStatement($cKey, $sqlCallback, $types, $params) {
		// Lazily prepare and cache the statement.
		if (!$this->stmtCache[$cKey]) {
			if (!($stmt = $this->mysqli->prepare( $sqlCallback instanceof \Closure ? $sqlCallback() : $sqlCallback ))) { throw new \Exception("Statement Error: {$this->mysqli->error}", $this->mysqli->errno); }
			$reflectMethod = new \ReflectionMethod('mysqli_stmt', 'bind_param');
			$args[] = $types;
			foreach (array_keys((array)$params) as $name) { $args[] = &$this->paramCache[$cKey][$name]; }
			if (!($reflectMethod->invokeArgs($stmt, $args))) { throw new \Exception("Bind Param Error: {$stmt->error}", $stmt->errno); }
			$this->stmtCache[$cKey] = $stmt;
		}
		foreach ((array)$params as $name=>$value) { $this->paramCache[$cKey][$name] = $value; }
		return $this->stmtCache[$cKey];
	}
1142935
public int[] executeBatchPreparedStatement(String statement, Collection inParamsBatch) throws SQLException {
		return executeBatchPreparedStatement(statement, inParamsBatch, true);
	}