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::$user = 'my_database_user';
DB::$password = 'my_database_password';
DB::$dbName = 'my_database_name';
DB::query("SELECT * FROM tbl");

DB::useDB()

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

DB::useDB('new-db-name');

new MeekroDB()

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

$db = new MeekroDB($host, $user, $pass, $dbName, $port, $encoding)
$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 mysqli's defaults will be used. Therefore, a practical example would look like this:

$db = new MeekroDB('localhost', 'mysql-username', 'mysql-password', 'my-database-name');