All database operations in ProcessWire are performed via this PDO-style database class.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireDatabasePDO class also inherits all the methods and properties of: Wire.

PDO / Custom / Sanitization

Show “$database”             Show Arguments        


boolInitiates a transaction
boolCommits a transaction
stringFetch the SQLSTATE associated with the last operation on the statement handle
arrayFetch extended error information associated with the last operation on the database handle
bool or intExecute an SQL statement string
$database->getAttribute(int $attribute)
mixedRetrieve a database connection attribute
boolChecks if inside a transaction
stringReturns the ID of the last inserted row or sequence value
PDOReturn the actual current PDO connection instance
$database->prepare(string $statement)
PDOStatementPrepare an SQL statement for accepting bound parameters
$database->query(string $statement)
PDOStatementExecutes an SQL statement, returning a result set as a PDOStatement object
$database->quote(string $str)
stringQuote and escape a string value
boolRolls back a transaction
$database->setAttribute(int $attribute, mixed $value)
boolSets an attribute on the database handle


WireDatabaseBackupRetrieve new instance of WireDatabaseBackups ready to use with this connection
(nothing)Close the PDO connection
$database->execute(\PDOStatement $query)
boolExecute a PDO statement, with retry and error handling
arrayGet array of all tables in this database.
$database->getVariable(string $name)
string or intGet the value of a MySQL variable
$database->isOperator(string $str)
boolIs the given string a database comparison operator?
array or boolLog a query, or return logged queries
string or boolGet SQL mode, set SQL mode, add to existing SQL mode, or remove from existing SQL mode


$database->escapeCol(string $col)
stringSanitize a column name for _a-zA-Z0-9
$database->escapeLike(string $like)
stringEscape a string value, plus escape characters necessary for a MySQL 'LIKE' phrase
$database->escapeStr(string $str)
stringEscape a string value, same as $db->quote() but without surrounding quotes
$database->escapeTable(string $table)
stringSanitize a table name for _a-zA-Z0-9
$database->escapeTableCol(string $str)
stringSanitize a table.column string, where either part is optional
$database->quote(string $str)
stringQuote and escape a string value

Additional methods and properties

In addition to the methods and properties above, WireDatabasePDO also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.84