ManaPHP\Db::execute PHP Method

execute() public method

Use this method only when the SQL statement sent to the server does n't return any rows Inserting data $success = $connection->execute("INSERT INTO robots VALUES (1, 'Boy')"); $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Boy'));
public execute ( string $sql, array $bind = [] ) : integer
$sql string
$bind array
return integer
    public function execute($sql, $bind = [])
    {
        $this->_sql = preg_replace('#\\[([a-z_][a-z0-9_]*)\\]#i', '`\\1`', $sql);
        $this->_bind = $bind;
        $this->_affectedRows = 0;
        $this->fireEvent('db:beforeQuery');
        try {
            if (count($bind) !== 0) {
                $statement = $this->_executePrepared($this->_pdo->prepare($this->_sql), $bind);
                $this->_affectedRows = $statement->rowCount();
            } else {
                $this->_affectedRows = $this->_pdo->exec($this->_sql);
            }
        } catch (\PDOException $e) {
            throw new DbException(':message . ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind', ['message' => $e->getMessage(), 'sql' => $this->_sql, 'bind' => json_encode($this->_bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
        }
        if (is_int($this->_affectedRows)) {
            $this->fireEvent('db:afterQuery');
        }
        return $this->_affectedRows;
    }