MeekroDB Quick Start Docs FAQ
Download GitHub


Is this project still maintained in 2023?

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::queryWalk() to retrieve and process the data one row at a time. Learn more about it on the retrieving data page.

I'm using queryWalk(), and I'm getting an "out of sync" error!

If you use DB::queryWalk(), you must either consume the entire result set or free it. If you do not, you'll get an out of sync error from MySQL when you run your next query. You can "consume" the result set by running next() until it returns false, or you can free the remaining results by running free(). Read the queryWalk() documentation on the retrieving data page for more details.

How do I test if an INSERT was successful?

DB::insert() does not return anything if the operation was successful. If an INSERT fails, MySQL treats this as an error and an exception will be thrown.

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?

You can use %% to escape the % character, just like you would with printf().

DB::queryFirstField("SELECT DATE_FORMAT(created_at, '%%H:%%i:%%s') 
    FROM accounts WHERE id=%i", 15);