$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?        

Common

NameReturnSummary 
$database->debugMode bool 
$database->escapeOperator(string $operator)
stringSanitize comparison operator 
$database->getCharset()
stringGet current database charset (lowercase) 
$database->getColumns(string $table)
arrayGet all columns from given table 
$database->getEngine()
stringGet current database engine (lowercase) 
$database->getIndexes(string $table)
arrayGet all indexes from given table 
$database->getPrimaryKey(string $table)
string arrayGet column(s) or info for given table’s primary key/index 
$database->getRegexEngine()
stringGet the regular expression engine used by database 
$database->getServerType()
stringGet server type, one of MySQL, MariDB, Percona, etc. 
$database->getStopwords()
arrayGet all fulltext stopwords for database engine 
$database->getTime()
string intGet current date/time ISO-8601 string or UNIX timestamp according to database 
$database->getVersion()
stringGet MySQL/MariaDB version 
$database->indexExists(string $table, string $indexName)
bool arrayDoes table have an index with given name? 
$database->isStopword(string $word)
boolIs given word a fulltext stopword for database engine? 
$database->renameColumn(string $table, string $oldName, string $newName)
boolRename a table column without changing type 
$database->renameColumns(string $table, array $columns)
intRename table columns without changing type 

PDO

NameReturnSummary 
$database->allowTransaction()
boolAllow a new transaction to begin right now? (i.e. supported and not already in one) 
$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)
PDOStatement WireDatabasePDOStatementPrepare 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)? 

Custom

NameReturnSummary 
$database->backups()
WireDatabaseBackupRetrieve new instance of WireDatabaseBackups ready to use with this connection 
$database->closeConnection()
(nothing)Close the PDO connection 
$database->columnExists(string $table)
bool arrayDoes the given column exist in given table? 
$database->execute(\PDOStatement $query)
boolExecute a PDO statement, with retry and error handling 
$database->getTables()
arrayGet array of all tables in this database. 
$database->getVariable(string $name)
string nullGet the value of a MySQL variable 
$database->isOperator(string $str)
boolIs the given string a database comparison operator? 
$database->queryLog()
array bool intLog a query, start/stop query logging, or return logged queries 
$database->sqlMode()
string boolGet SQL mode, set SQL mode, add to existing SQL mode, or remove from existing SQL mode 
$database->tableExists(string $table)
boolDoes the given table exist in this database? 

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.185

Twitter updates

  • ProcessWire 3.0.185 (dev) core updates, plus new Session Allow module— More
    17 September 2021
  • Three new ProcessWire Textformatter modules: Find/Replace, Markdown in Markup, and Emoji— More
    3 September 2021
  • This week we have a new master version released after a year in the making. With nearly 40 pull requests, hundreds of new additions and more than 100 issue reports resolved, this new version has a ton of great new stuff— More
    27 August 2021

Latest news

  • ProcessWire Weekly #388
    In the 388th issue of ProcessWire Weekly we'll check out the latest core update, introduce two new third party modules, and more. Read on!
    Weekly.pw / 16 October 2021
  • ProcessWire 3.0.184 new master/main version
    This week we have a new master/main version released after a full year in the making. As you might imagine, this new version has a ton of great new stuff and we’ll try to cover much of it here.
    Blog / 27 August 2021
  • Subscribe to weekly ProcessWire news

“…building with ProcessWire was a breeze, I really love all the flexibility the system provides. I can’t imagine using any other CMS in the future.” —Thomas Aull