MeekroDB Quick Start Docs FAQ
Download GitHub

Static vs Object Oriented

Most PHP projects access only one database from one database server. In this context, passing a $db variable every which way is too verbose. Therefore, we encourage you to use MeekroDB's "static mode" by default. All of the examples in this manual, including those in the Quick Start Guide, rely on it. For example:

DB::$dsn = 'mysql:host=localhost;dbname=meekrodb';
DB::$user = 'my_database_user';
DB::$password = 'my_database_password';
DB::query("SELECT * FROM tbl");


You can access multiple databases with the static instance. Just switch databases like this:


new MeekroDB()

If you want to access more than one database at the same time, you can create multiple MeekroDB instances.

$dsn = 'mysql:host=localhost;dbname=meekrodb';
$db = new MeekroDB($dsn, $user, $password);
$db->query("SELECT * FROM tbl");

The arguments to new MeerkoDB() are all optional. Any that are ommitted will be read from the current static instance of MeekroDB, or the defaults will be used. The DSN used for the first argument is the same one that PDO uses. An assoc array of PDO attributes can optionally be passed as a 4th argument.