All database operations in ProcessWire are performed via this PDO-style database class.
ProcessWire creates the database connection automatically at boot and this is available from the
$database API variable. If you want to create a new connection on your own, choose either option A or B below:
// The following are required to construct a WireDatabasePDO $dsn = 'mysql:dbname=mydb;host=myhost;port=3306'; $username = 'username'; $password = 'password'; $driver_options = ; // optional // Construct option A $db = new WireDatabasePDO($dsn, $username, $password, $driver_options); // Construct option B $db = new WireDatabasePDO([ 'dsn' => $dsn, 'user' => $username, 'pass' => $password, 'options' => $driver_options, // optional 'reader' => [ // optional 'dsn' => '…', … ], … ]);
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.
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.209