MeekroDB

The Simple PHP MySQL Library

 

Like MeekroDB?

MeekroDB is open source software. It is free for personal use, but you must buy a license to use it in a commercial project.

What is MeekroDB?

MeekroDB is a PHP MySQL library that lets you get more done with fewer lines of code, and makes SQL injection 100% impossible.

MeekroDB has been Google's #1 search result for "php mysql library" for over 2 years, 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.

MeekroDB has useful features that PDO does not.

Classic Select

Standard PHP forces you to remember to escape every variable. Don't drop any quotes or forget any escapes, or you're in trouble!
 
      $mysqli->query("SELECT * FROM login WHERE username='"
        . $mysqli->real_escape_string($username) . "' AND password='"
        . $mysqli->real_escape_string($password) . "'");
      
MeekroDB takes care of quotes and escaping for you.
 
      DB::query("SELECT * FROM login WHERE username=%s AND password=%s", $username, $password);
      

Large Update or Insert

Standard PHP forces you to count the column names yourself to make sure everything goes into the right field. Don't forget to escape all strings, too, if you don't want to get hacked!
      $mysqli->query("INSERT INTO mytable (`name`, `rank`, `location`, `age`, `intelligence`) 
        VALUES ('" . $mysqli->real_escape_string($name) . "','"
        . $mysqli->real_escape_string($rank) . "','"
        . $mysqli->real_escape_string($location) . "',"
        . intval($age) . ",'"
        . $mysqli->real_escape_string($intelligence) . "')");
    
MeekroDB lets you INSERT with a very simple format. You can tell at a glance if everything is right.
      DB::insert('mytable', array(
        'name' => $name,
        'rank' => $rank,
        'location' => $location,
        'age' => $age,
        'intelligence' => $intelligence
      ));
    

Grab One Row or Field

Standard PHP makes it a pain to grab the contents of a single MySQL field.
      $result = $mysqli->query("SELECT COUNT(*) FROM accounts");
      $row = $result->fetch_assoc();
      $number_accounts = $row['COUNT(*)'];
    
MeekroDB makes it trivial.
      $number_accounts = DB::queryFirstField("SELECT COUNT(*) FROM accounts");
    
If you want to grab a row, that's trivial too.
      $account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
    

Nested Transactions (MySQL 5.5 only)

Standard PHP/MySQL syntax makes nested transactions annoying and difficult. You have to learn a new "savepoint" syntax and manually keep track of how many transactions deep you currently are.
      $mysqli->query("START TRANSACTION"); // outer transaction
      // .. some queries..
      $mysqli->query("SAVEPOINT PT1"); // inner transactions
      // .. some queries..
      $mysqli->query("RELEASE SAVEPOINT PT1"); // commit inner transaction
      // .. some queries..
      $mysqli->query("COMMIT"); // commit outer transaction
    
MeekroDB lets you use the same transaction syntax you're used to.
      DB::$nested_transactions = true;
      DB::startTransaction(); // outer transaction
      // .. some queries..
      $depth = DB::startTransaction(); // inner transaction
      echo $depth . 'transactions are currently active'; // 2
      
      // .. some queries..
      DB::commit(); // commit inner transaction
      // .. some queries..
      DB::commit(); // commit outer transaction
    

Prefer Object-Oriented?

We recommend the static class approach (as shown in the examples above) because most projects don't need multiple database connections, and it's annoying to pass $db objects around all the time. Still, MeekroDB works the same way in both static and object-oriented modes, so you can take your pick.
      $mdb = new MeekroDB('localhost', 'username', 'password');
      $result = $mdb->query("SELECT * FROM login WHERE username=%s AND password=%s", 
        $username, $password);
    

But how is this better than PDO?

PDO is a commonly used library for PHP/MySQL work, but it's nowhere near as good as MeekroDB.

Give MeekroDB a try?

Download MeekroDB and try it out yourself! See our quick start guide to find out how easily you can get started with it.

Copyright (C) 2008-2014 :: :: LGPL v3 :: GitHub Tracker