$database API variable / WireDatabasePDO class

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.

Show $var?             Show args?        

PDO

NameReturnSummary 
$database->beginTransaction()
boolInitiates a transaction 
$database->commit()
boolCommits a transaction 
$database->errorCode()
stringFetch the SQLSTATE associated with the last operation on the statement handle 
$database->errorInfo()
arrayFetch extended error information associated with the last operation on the database handle 
$database->exec($statement)
bool intExecute an SQL statement string 
$database->getAttribute(int $attribute)
mixedRetrieve a database connection attribute 
$database->inTransaction()
boolChecks if inside a transaction 
$database->lastInsertId()
stringReturns the ID of the last inserted row or sequence value 
$database->pdo()
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 
$database->rollBack()
boolRolls back a transaction 
$database->setAttribute(int $attribute, mixed $value)
boolSets an attribute on the database handle 
$database->supportsTransaction()
boolAre transactions available with current DB engine (or table)? 

Sanitization

NameReturnSummary 
$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.133

Twitter updates

  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019
  • New post: This week we've added WEBP support in ProcessWire thanks to a GitHub pull request from Horst Nogajski. This enables you to have highly optimized image output in PW and I think you’ll really like the difference it makes— More
    24 May 2019

Latest news

  • ProcessWire Weekly #267
    In the 267th issue of ProcessWire Weekly we're going to cover the latest changes in the development branch of ProcessWire, introduce a new module called MarkupMenu, and highlight a brand new site of the week. Read on!
    Weekly.pw / 22 June 2019
  • ProcessWire 3.0.133 core updates
    ProcessWire 3.0.133 adds a useful new $page->meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type. Read on for all the details, examples and screenshots.
    Blog / 14 June 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer