MeekroDB Quick Start Docs FAQ
Download GitHub

Misc Methods and Variables

DB::useDB()

Switch to a different database.

DB::useDB('my_other_database');

DB::tableList()

Get an array of the tables in the requested database. If no database is specified, use the current database.

$current_db_tables = DB::tableList();
$other_db_tables = DB::tableList('other_db');

foreach ($other_db_tables as $table) {
  echo "Table Name: $table\n";
}

DB::columnList()

Get an array of the columns in the requested table in the current database.

$columns = DB::columnList('accounts');

foreach ($columns as $name => $details) {
  echo "Column: $name\n";
  echo "Type: " . $details['type'] . "\n";
  echo "Null? " . $details['null'] . "\n";
  echo "Key: " . $details['key'] . "\n";
  echo "Default: " . $details['default'] . "\n";
  echo "Extra: " . $details['extra'] . "\n";
}

DB::disconnect()

Drop any existing MySQL connections. If you run a query after this, it will automatically reconnect.

DB::disconnect(); // drop mysqli connection

DB::get()

Return the underlying mysqli object.

$mysqli = DB::get();

DB::lastQuery()

Return the last query (whether or not it succeeded).

$query = DB::lastQuery();

DB::parse()

Parse a query with args just like DB::query() would, but return it instead of executing

$query = DB::parse("SELECT * FROM accounts WHERE name=%s AND age=%i", 'Joe', 15);
// $query: SELECT * FROM accounts WHERE name='Joe' AND age=15

DB::$param_char

Change the character that appears before parameters in MeekroDB queries. The default is %.

DB::$param_char = ':';
$results = DB::query("SELECT * FROM accounts WHERE email=:s", '[email protected]');

DB::$reconnect_after

If it's been at least this long since our last query, re-connect to the database before running another query. Defaults to 4 hours, since MySQL's default wait_timeout is 8 hours.

// if MySQL was configured with a wait_timeout of 60 seconds, we should set
// our reconnect to 30 seconds like this
DB::$reconnect_after = 30;