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

PDO

Name Return Summary  
$database->beginTransaction() bool Initiates a transaction
$database->commit() bool Commits a transaction
$database->errorCode() string Fetch the SQLSTATE associated with the last operation on the statement handle
$database->errorInfo() array Fetch extended error information associated with the last operation on the database handle
$database->exec($statement) bool or int Execute an SQL statement string
$database->getAttribute(int $attribute) mixed Retrieve a database connection attribute
$database->inTransaction() bool Checks if inside a transaction
$database->lastInsertId() string Returns the ID of the last inserted row or sequence value
$database->pdo() PDO Return the actual current PDO connection instance
$database->prepare(string $statement) PDOStatement Prepare an SQL statement for accepting bound parameters
$database->query(string $statement) PDOStatement Executes an SQL statement, returning a result set as a PDOStatement object
$database->quote(string $str) string Quote and escape a string value
$database->rollBack() bool Rolls back a transaction
$database->setAttribute(int $attribute, mixed $value) bool Sets an attribute on the database handle

Custom

Name Return Summary  
$database->backups() WireDatabaseBackup Retrieve new instance of WireDatabaseBackups ready to use with this connection
$database->closeConnection() (nothing) Close the PDO connection
$database->execute($query) bool Execute a PDO statement, with retry and error handling
$database->getTables() array Get array of all tables in this database.
$database->getVariable(string $name) string or int Get the value of a MySQL variable
$database->isOperator(string $str) bool Is the given string a database comparison operator?
$database->queryLog() array or bool Log a query, or return logged queries
$database->sqlMode() string or bool Get SQL mode, set SQL mode, add to existing SQL mode, or remove from existing SQL mode

Sanitization

Name Return Summary  
$database->escapeCol(string $col) string Sanitize a column name for _a-zA-Z0-9
$database->escapeLike(string $like) string Escape a string value, plus escape characters necessary for a MySQL 'LIKE' phrase
$database->escapeStr(string $str) string Escape a string value, same as $db->quote() but without surrounding quotes
$database->escapeTable(string $table) string Sanitize a table name for _a-zA-Z0-9
$database->escapeTableCol(string $str) string Sanitize a table.column string, where either part is optional
$database->quote(string $str) string Quote 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: