We released v3 (a major upgrade) in 2024, actually! It's an overhaul that enables support for SQLite and Postgres, in addition to MySQL. It also features an "ORM" (object-relational manager) that offers a more modern way to interact with your database.
In general, there aren't many new releases 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.
MeekroDB supports all versions of PHP 7 and PHP 8.
We actually just added support for Postgres and SQLite in v3! You can read the details on the connection docs, but it works pretty much like you'd expect.
First, v2 is still perfectly fine, and is considered "stable." Aside from a handful of bug fixes (that don't affect most people), v3 introduces two major things: support for non-MySQL databases such as SQLite, and the MeekroORM object-relational manager. If you don't care about these things, you probably don't need to upgrade.
If you do choose to upgrade, we've tried to make the process as painless as possible. You should just be able to drop-in v3 and everything will keep working the same -- with one exception. If you're using the object-oriented MeekroDB, the arguments to the constructor (new MeekroDB(...)
) are different. See here for details.
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.
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.
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.
MeekroDB v2.5 and up 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.
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.
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.
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";
}
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);