Execute an INSERT, UPDATE or DELETE statement

@param      string  $sql     SQL statement to execute (INSERT, UPDATE,
DELETE ...)
@param      array   $params  Bind params

@return     bool    True if rows affected > 0
483457
public function rawExec(string $sql, array $params=[]): bool
  {
    $result = false;

    # Sanity check
    if (empty($sql)) {
      return $result;
    }

    # Obtain transaction, unelss already in a transaction
    $autoCommit = $this->beginTransaction();

    # Prepare
    if ($sth = $this->prepare($sql)) {
      # Binds
      foreach ($params as $bind=>$value) {
        $sth->bindValue( ':'.\ltrim($bind,':'), $value);
      }

      # Execute statement
      if ($sth->execute()) {
        $result = $sth->rowCount() > 0;
      }

      # Close cursor
      $sth->closeCursor();
    }

    # If we had a loacl transaction, commit it
    if ($autoCommit) $this->commit();

    return $result;
  }
686312
public function prepare(string $sql, array $params = []): Statement
    {
        if (!$stmt = $this->connection->prepare($sql)) {
            $error = [
                'error' => $this->connection->error,
                'errno' => $this->connection->errno,
                'sqlstate' => $this->connection->sqlstate
            ];

            throw new SqlException('Failed to prepare statement', [$error], $sql, $params);
        }

        if (!empty($params)) {
            if (!$stmt->bind_param(self::getMysqlParamTypes($params), ...$params)) {
                throw new SqlException('Failed to bind params', $stmt->error_list, $sql, $params);
            }
        }

        return new Statement($stmt, $this->usedPrepare, $sql, $params);
    }
1228485
public function executeRaw($sql) {
        if (!is_string($sql)) throw new IllegalTypeException('Illegal type of parameter $sql: '.gettype($sql));
        if (!$this->isConnected())
            $this->connect();

        // execute statement
        try {
            $result = mysql_query($sql, $this->hConnection);
            $result || trigger_error('SQL-Error '.mysql_errno($this->hConnection).': '.mysql_error($this->hConnection), E_USER_ERROR);
        }
        catch (\Exception $ex) {
            $ex = new DatabaseException($ex->getMessage(), mysql_errno($this->hConnection), $ex);
            throw $ex->addMessage('Database: '.$this->getConnectionDescription().NL.'SQL: "'.$sql.'"');
        }

        $affected = 0;

        // track last_insert_id
        $id = mysql_insert_id($this->hConnection);
        if ($id) $this->lastInsertId = $id + ($affected=mysql_affected_rows($this->hConnection)) - 1;

        // track last_affected_rows
        if (!is_resource($result)) {                                               // a row returning statement never modifies rows
            $version = $this->getVersionNumber();
            if ($version < 5005005) $pattern = '/^\s*(INSERT|UPDATE|DELETE)\b/i';   // < 5.5.5.
            else                    $pattern = '/^\s*(INSERT|UPDATE|DELETE|ALTER\s+TABLE|LOAD\s+DATA\s+INFILE)\b/i';
            if (preg_match($pattern, $sql)) {
                if (!$id) $affected = mysql_affected_rows($this->hConnection);
                $this->lastAffectedRows = $affected;
            }
        }
        return $result;
    }
607851
public function execute($sql = null, $parameters = array()) {
        if (empty($sql)) {
            return null;
        }
        foreach ($parameters as $key => $item) {
            Str::bindParam($sql, $key + 1, $item, is_numeric($item) ? 'INT' : 'STR');
        }
        $this->result = mysql_query($sql, $this->driver);
        Factory::log()->info(sprintf('MYSQL: %s => %s', $sql,
            $this->getError()));
        return $this->result;
    }
1080740
public function bind($sql, array $params=array())
    {
        return $this->_bindInto('\?', $sql, $params, function($binder, $param) use ($sql) {
            return $binder->sqlValue($param);
        });
    }
954113
protected function insert( $sql, $params = null ) {
		$stmt = $this->dbh->prepare( $sql );
		try {
			$this->transactionStart();
			$stmt->execute( $params );
			$rowid = $this->dbh->lastInsertId();
			$this->transactionCommit();
			return $rowid;

		} catch ( PDOException $e ) {
			$this->transactionRollback();
			$this->logger->error( 'Insert failed.', [
				'method' => __METHOD__,
				'exception' => $e,
				'sql' => $sql,
				'params' => $params,
			] );
			return false;
		}
	}
1038594
public function fetch($sql, $params = array())
    {
        $stmt = $this->db->prepare($sql);
        $stmt->execute($params);
        if (!$res = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            return false;
        }

        return $res;
    }
909186
protected function _modifyParams(&$sql, &$params) {
        if (is_array($sql)) {
            if (count($sql) < 2) {
                throw new \InvalidArgumentException('If $sql is array, it needs to have at least 2 elements: (0) sql query, string and (1) parameters (single value or array).');
            }
            if ((count($params) > 0)) {
                throw new \InvalidArgumentException('$sql is array, $params should be empty in this case.');
            }
            $params = $sql[1];
            $sql = $sql[0];
        }
        if (!is_array($params)) {
            $params = array ($params);
        }
    }
248989
public function execute($sql, array $parameters = [])
    {
        $sth = $this->prepare($sql);
        $sth->execute($parameters);
        return $sth;
    }
145107
public static function execute( $sql, $parameters = null, $connection = null, $fetchMode = \PDO::FETCH_ASSOC )
    {
        self::$_statement = self::createStatement( $sql, $connection, $fetchMode );

        if ( empty( $parameters ) )
        {
            return self::$_statement->execute();
        }

        return self::$_statement->execute( $parameters );
    }
577075
public function createSqlCommand($sql,$params=array())
	{
		$command=$this->_connection->createCommand($sql);
		$this->bindValues($command,$params);
		return $command;
	}
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());
        }
    }
239648
public function statement($sql, $bindings = array())
		{
			list($statement, $result) = $this->execute($sql, $bindings);
			return $result;
		}
920027
public function exec($sql, array $parameters = [])
    {
        $statement = $this->executeQuery($sql, $parameters);

        return $statement->rowCount();
    }
970381
public boolean execute(Sql sql) throws SQLException {
		
		long start =  System.currentTimeMillis();
		
		if (sql.validate() == false) {
			return false;
		}
		
		boolean result = false;
		
		PreparedStatement stmt = null;
		try {
			stmt = this.createStatment(conn, sql);
			stmt.execute();
			
			result = true;
		} catch (SQLException e) {
			throw e;
		} finally {
			try {
				if (stmt != null && stmt.isClosed() == false) {
					stmt.close();
				}
			} catch (SQLException e) {
				logger.error(e.getMessage(), e);
			}
		}
		
		logger.debug(String.format("Execute %s used %d ms", sql.getSql(), System.currentTimeMillis() - start));

		return result;
	}
189939
public function execute(string $sql, $bind = []): Statement
    {
        $this->operation = 'execute';
        $this->sql = $sql;
        $this->params = $bind;
        return $this;
    }
1155792
public function getValue($sql, $params = null)
    {
        $stmt = $this->execute($sql, $params);

        return $stmt->fetchColumn(0);
    }