MeekroDB Quick Start Docs FAQ
Download GitHub


Is this project still maintained in 2020?

There aren't many new releases these days because the project has reached a "stable" state and there are no known bugs. However, if I find out about any, I'm happy to fix and put out a new release. You can report bugs on GitHub.

How can I be sure that MeekroDB is actually safe?

MeekroDB has been Google's #1 search result for "php mysql library" since 2012 and has thousands of deployments worldwide. In that time, we have never had any security issues. The code is developed with a healthy level of paranoia, and automated unit tests check every new version for problems. Our code is open source, and many developers have examined it for security flaws and found none. While there is no such thing as a 100 percent guarantee, an excellent security track record like ours is a good place to start.

Can I have multiple MySQL connections?

Absolutely! The easiest thing to do is just switch between databases with DB::useDB(). If you actually want multiple connections, you should use new MeekroDB() to create non-static instances of MeekroDB.

I have a long-running PHP script, and keep getting "MySQL server has gone away".

You need the line mysqli.reconnect = 1 in your php.ini file. This file might be in a different place depending on your server, but Ubuntu has /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini. Because of PHP restrictions, there is no way to change this setting without having root and MeekroDB can't set it for you. See PHP documentation on this for more.

I'm pulling a very large data set from MySQL, and keep getting out-of-memory errors.

You should use DB::queryRaw() to get a mysqli_result object, and then use PHP's mysqli_result->fetch_assoc to grab rows one at a time.

When I use insert(), it tries to insert a NULL value for a missing variable, but my table columns are set to NOT NULL.

By default, DB::insert() uses NULL if you pass a variable that's unset or set to null. You can change this by setting DB::$usenull to false.

How do I test if an INSERT was successful?

DB::insert() does not return anything. If an INSERT operation fails, MySQL treats this as an error (same as if you gave an invalid MySQL query). By default, this means MeekroDB's error handler will run, but you can change that behavior with the variables $error_handler and $throw_exception_on_error.

On the other hand, a DB::insertIgnore() will not trigger an error if the INSERT fails. In this case, you can check if it worked by checking the DB::affectedRows() count.

How do I use MySQL's DATE_FORMAT(), since %d has a special meaning to MeekroDB?

The character that MeekroDB's placeholders start with defaults to %, but can be changed with DB::$param_char.

DB::$param_char = ':';
DB::query("SELECT * FROM accounts WHERE email=:s", '');
DB::queryFirstField("SELECT DATE_FORMAT('2009-10-04 22:23:00', '%H:%i:%s')");