PDOWrapper::execute PHP Method

execute() public method

- executes a query that modifies the database
public execute ( string $query, $params = [] ) : mixed
$query string - the SQL query we are executing
return mixed - the affected rows, false on failure
    public function execute($query, $params = array())
    {
        try {
            // use the master connection
            $pdo_connection = $this->getMaster();
            // prepare the statement
            $pstmt = $pdo_connection->prepare($query);
            // bind each parameter in the array
            foreach ((array) $params as $key => $val) {
                $pstmt->bindValue($key, $val);
            }
            // execute the query
            $result = $pstmt->execute();
            // only if return value is false did this query fail
            return $result == true ? $pstmt->rowCount() : false;
        } catch (PDOException $e) {
            if (self::$LOG_ERRORS == true) {
                error_log('DATABASE WRAPPER::' . print_r($e, true));
            }
            $this->pdo_exception = $e;
            return false;
        } catch (Exception $e) {
            if (self::$LOG_ERRORS == true) {
                error_log('DATABASE WRAPPER::' . print_r($e, true));
            }
            $this->pdo_exception = $e;
            return false;
        }
    }