MeekroDB Quick Start Docs FAQ
Download GitHub

MeekroDB

The Simple PHP MySQL Library

What is MeekroDB?

MeekroDB is a PHP MySQL library that will let you get more done with fewer lines of code while making SQL injection 100% impossible.

MeekroDB has been a top search result for "php mysql library" since 2013, and has thousands of deployments worldwide.

MeekroDB has a perfect security track record. No bugs relating to security or SQL injection have ever been discovered.

How's it better than PDO?

Check out some of the features demonstrated in the examples below. PDO doesn't have most of them, or requires more than a single line of code to make them work. Also, PDO doesn't support static class operation so you're stuck passing $db options around.

Examples

Select Multiple Rows

Run a query and get back multiple rows with one line of code. The inputs are properly escaped, and you get back an array of assoc arrays that's easy to work with!

$results = DB::query("SELECT * FROM accounts WHERE username=%s AND password=%s", $username, $password);
foreach ($results as $result) {
  echo $result['username'] . '-' . $result['password'] . "\n";
}

Select Single Row

Sometimes you just need one row. This returns an assoc array.

$user = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", $username);

Select Single Field

Need just one field? Don't waste time with the rest!

$count = DB::queryFirstField("SELECT COUNT(*) FROM accounts");

Insert an Assoc Array

Don't waste time trying to format an INSERT property, just pass an assoc array. You can also do INSERT IGNORE, UPDATE, and even INSERT .. ON DUPLICATE KEY UPDATE with a similar syntax!

DB::insert('accounts', [
  'username' => $username,
  'password' => $password,
]);

Nested Transactions

Get nested transactions with very simple syntax! MeekroDB will transparently convert inner transactions to SAVEPOINTS!

DB::$nested_transactions = true;
DB::startTransaction(); // START TRANSACTION
// .. some queries..
$depth = DB::startTransaction(); // SAVEPOINT PT1
echo $depth . 'transactions are currently active'; // 2

// .. some queries..
DB::commit(); // RELEASE SAVEPOINT PT1
// .. some queries..
DB::commit(); // commit outer transaction

Prefer Object-Oriented?

Most projects only use one database and don't need multiple database objects. If you do, you can create them like this.

$mdb = new MeekroDB('localhost', 'username', 'password');
$result = $mdb->query("SELECT * FROM login WHERE username=%s AND password=%s", 
  $username, $password);

Ready to give it a try?

Check out our Quick Start Guide!