MeekroDB Quick Start Docs FAQ
Download GitHub

Connection Variables

Before you run any SQL commands, you must set the variables below. MeekroDB doesn't actually establish a MySQL connection until you run your first command!

DB::$dsn = 'mysql:host=localhost;dbname=meekrodb';
DB::$user = 'my_database_user';
DB::$password = 'my_database_password';

What is a DSN?

A DSN is a string describing a database connection, in a format that has become standard for PHP. It has a prefix such as mysql:, and then a series of key=value pairs separated by semicolons. Valid keys for MySQL are: host, port, dbname, unix_socket, charset. Here are several example DSNs:

mysql:host=localhost;dbname=testdb
mysql:host=localhost;port=3307;dbname=testdb
mysql:unix_socket=/tmp/mysql.sock;dbname=testdb

SSL Connections

If you're connecting to MySQL over SSL, you may also need to set this:

DB::$connect_options = [
    PDO::MYSQL_ATTR_SSL_KEY => '',
    PDO::MYSQL_ATTR_SSL_CERT => '',
    PDO::MYSQL_ATTR_SSL_CA => '',
    PDO::MYSQL_ATTR_SSL_CAPATH => '',
];

The options here are imported directly from PHP's PDO library. You usually don't need to change them, but if you really want to, you can find a complete list of the generic ones here and the MySQL-specific ones here.

These variables only have an effect when a connection is being established. Once you're connected, changing them has no effect. If you use DB::disconnect(), you can change these variables. It will then use the new values to re-connect once you run another query.

Databases other than MySQL

In addition to MySQL, MeekroDB fully supports SQLite and Postgres. You can connect by setting the appropriate DSN, such as:

pgsql:host=localhost;port=5432;dbname=meekrodb
sqlite:
sqlite::memory:
sqlite:/opt/databases/mydb.sq3

MeekroDB has a few limitations with SQLite and Postgres. These are caused by how the databases themselves work, and therefore aren't something we could fix in a future release:

  • insertUpdate() and insertIgnore() don't work for SQLite until version 3.35.0
  • insertUpdate() and insertIgnore() don't work for Postgres
  • useDB() doesn't work for either SQLite or Postgres