PHPackages                             sergeytsalkov/meekrodb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sergeytsalkov/meekrodb

ActiveLibrary[Database &amp; ORM](/categories/database)

sergeytsalkov/meekrodb
======================

The Simple PHP/MySQL Library

v3.1.5(3mo ago)341387.0k—1%74[2 issues](https://github.com/SergeyTsalkov/meekrodb/issues)9LGPL-3.0PHPPHP &gt;=7.1.0

Since Jun 8Pushed 2mo ago33 watchersCompare

[ Source](https://github.com/SergeyTsalkov/meekrodb)[ Packagist](https://packagist.org/packages/sergeytsalkov/meekrodb)[ Docs](http://www.meekro.com)[ RSS](/packages/sergeytsalkov-meekrodb/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (19)Used By (9)

MeekroDB -- The Simple PHP MySQL Library
========================================

[](#meekrodb----the-simple-php-mysql-library)

Learn more:

MeekroDB is:

- A PHP MySQL library that lets you **get more done with fewer lines of code**, and **makes SQL injection 100% impossible**.
- Google's #1 search result for "php mysql library" since 2013, with **thousands of deployments worldwide**.
- A library with a **perfect security track record**. No bugs relating to security or SQL injection have ever been discovered.
- Backwards and forwards-compatible, supporting all PHP versions **from PHP 5.6** all the way through the latest release of **PHP 8**.

Installation
============

[](#installation)

When you're ready to get started, see the [Quick Start Guide](http://www.meekro.com/quickstart.php) on our website.

### Manual Setup

[](#manual-setup)

Include the `db.class.php` file into your project and set it up like this:

```
require_once 'db.class.php';
DB::$dsn = 'mysql:host=localhost;dbname=meekrodb';
DB::$user = 'my_database_user';
DB::$password = 'my_database_password';
```

### Composer

[](#composer)

Add this to your `composer.json`

```
{
  "require": {
    "sergeytsalkov/meekrodb": "*"
  }
}
```

Code Examples
=============

[](#code-examples)

### Grab some rows from the database and print out a field from each row.

[](#grab-some-rows-from-the-database-and-print-out-a-field-from-each-row)

```
$accounts = DB::query("SELECT * FROM accounts WHERE type = %s AND age > %i", $type, 15);
foreach ($accounts as $account) {
  echo $account['username'] . "\n";
}
```

### Insert a new row.

[](#insert-a-new-row)

```
DB::insert('mytable', array(
  'name' => $name,
  'rank' => $rank,
  'location' => $location,
  'age' => $age,
  'intelligence' => $intelligence
));
```

### Grab one row or field

[](#grab-one-row-or-field)

```
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
$number_accounts = DB::queryFirstField("SELECT COUNT(*) FROM accounts");
```

### Use a list in a query

[](#use-a-list-in-a-query)

```
DB::query("SELECT * FROM tbl WHERE name IN %ls AND age NOT IN %li", array('John', 'Bob'), array(12, 15));
```

### Log all queries and errors

[](#log-all-queries-and-errors)

```
// log all queries and errors to file, or ..
DB::$logfile = '/home/username/logfile.txt';

// log all queries and errors to screen
DB::$logfile = fopen('php://output', 'w');
```

### Nested Transactions

[](#nested-transactions)

```
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
```

### Lots More - See:

[](#lots-more---see-httpmeekrocomdocs)

How is MeekroDB better than PDO?
================================

[](#how-is-meekrodb-better-than-pdo)

### Optional Static Class Mode

[](#optional-static-class-mode)

Most web apps will only ever talk to one database. This means that passing $db objects to every function of your code just adds unnecessary clutter. The simplest approach is to use static methods such as DB::query(), and that's how MeekroDB works. Still, if you need database objects, MeekroDB can do that too.

### Do more with fewer lines of code

[](#do-more-with-fewer-lines-of-code)

The code below escapes your parameters for safety, runs the query, and grabs the first row of results. Try doing that in one line with PDO.

```
$account = DB::queryFirstRow("SELECT * FROM accounts WHERE username=%s", 'Joe');
```

Or how about just one field?

```
$created_at = DB::queryFirstField("SELECT created_at FROM accounts WHERE username=%s", 'Joe');
```

### Work with list parameters easily

[](#work-with-list-parameters-easily)

Using MySQL's IN keyword should not be hard. MeekroDB smooths out the syntax for you, PDO does not.

```
$accounts = DB::query("SELECT * FROM accounts WHERE username IN %ls", array('Joe', 'Frank'));
```

### Simple inserts

[](#simple-inserts)

Using MySQL's INSERT should not be more complicated than passing in an associative array. MeekroDB also simplifies many related commands, including the useful and bizarre INSERT .. ON DUPLICATE UPDATE command. PDO does none of this.

```
DB::insert('accounts', array('username' => 'John', 'password' => 'whatever'));
```

### Nested transactions

[](#nested-transactions-1)

MySQL's SAVEPOINT commands lets you create nested transactions, but only if you keep track of SAVEPOINT ids yourself. MeekroDB does this for you, so you can have nested transactions with no complexity or learning curve.

```
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
```

### Flexible debug logging and error handling

[](#flexible-debug-logging-and-error-handling)

You can log all queries (and any errors they produce) to a file for debugging purposes. You can also add hooks that let you run your own functions at any point in the query handling process.

My Other Projects
=================

[](#my-other-projects)

A little shameless self-promotion!

- [Ark Server Hosting](https://arkservers.io) -- Ark: Survival Evolved server hosting by ArkServers.io!
- [brooce](https://github.com/SergeyTsalkov/brooce) - Language-agnostic job queue written in Go! Write your jobs in any language, schedule them from any language, run them anywhere!

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance84

Actively maintained with recent releases

Popularity57

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~288 days

Recently: every ~104 days

Total

17

Last Release

112d ago

Major Versions

v2.5.1 → v3.0.02024-06-11

v2.x-dev → v3.1.52026-01-27

PHP version history (5 changes)v2.2.0PHP &gt;=5.2.0

v2.4PHP &gt;=5.3.0

v3.0.0PHP &gt;=5.6.0

v3.1.0PHP &gt;=7.0.0

v3.1.4PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/03c94bf953d7fb340e3d5d9c8ae40f8f4ca03c76e0b4607c7519b4a1cbf9dde0?d=identicon)[SergeyTsalkov](/maintainers/SergeyTsalkov)

---

Top Contributors

[![SergeyTsalkov](https://avatars.githubusercontent.com/u/3589642?v=4)](https://github.com/SergeyTsalkov "SergeyTsalkov (272 commits)")[![magma1447](https://avatars.githubusercontent.com/u/1918311?v=4)](https://github.com/magma1447 "magma1447 (2 commits)")[![JuneTwooo](https://avatars.githubusercontent.com/u/1458019?v=4)](https://github.com/JuneTwooo "JuneTwooo (1 commits)")[![bcash](https://avatars.githubusercontent.com/u/570976?v=4)](https://github.com/bcash "bcash (1 commits)")[![mikedamm](https://avatars.githubusercontent.com/u/24718?v=4)](https://github.com/mikedamm "mikedamm (1 commits)")[![cgoedel](https://avatars.githubusercontent.com/u/116256446?v=4)](https://github.com/cgoedel "cgoedel (1 commits)")[![wadih](https://avatars.githubusercontent.com/u/1222066?v=4)](https://github.com/wadih "wadih (1 commits)")

---

Tags

databasemysqlpdomysqli

### Embed Badge

![Health badge](/badges/sergeytsalkov-meekrodb/health.svg)

```
[![Health](https://phpackages.com/badges/sergeytsalkov-meekrodb/health.svg)](https://phpackages.com/packages/sergeytsalkov-meekrodb)
```

###  Alternatives

[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)[jv2222/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

87311.3k2](/packages/jv2222-ezsql)[codesvault/howdy-qb

Mysql Query Builder for WordPress

371.2k1](/packages/codesvault-howdy-qb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
