MeekroDB Quick Start Docs FAQ
Download GitHub

FAQ

Is this project still maintained in 2024?

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.

Does this project work with the latest version of PHP?

MeekroDB supports every PHP version from 5.3 to 8.*.

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 many 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".

If your long-running script is idle longer than MySQL's wait_timeout setting (8 hours by default), MySQL will disconnect you. The next time your script tries to run a query, it'll return an error.

The latest version of MeekroDB (v2.5, released in Sept 2023) actually solves this problem by auto-reconnecting you. Just upgrade and you'll be fine. If you want more details on this, look up $reconnect_after in our docs.

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?

If DB::insert() did not result in a MySQL error and a MeekroDBException being thrown, that's a pretty good indication that it succeeded. If that's not convincing enough (or you're using DB::insertIgnore()), you can actually check the results:

$inserted_rows = DB::insert(...);
if ($inserted_rows > 0) {
    echo "We inserted some stuff!\n";
}

// this does the same thing as the above
if (DB::affectedRows() > 0) {
    echo "We inserted some stuff!\n";
}

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);