PHPackages                             anomalous/iron-sql - 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. anomalous/iron-sql

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

anomalous/iron-sql
==================

PHP database adapter for MySQL Databases. Inspired by MeekroDB.

2.5(7y ago)032[1 issues](https://github.com/2blane/IronSQL/issues)LGPL-3.0PHPPHP &gt;=5.2.0

Since Jun 8Pushed 7y agoCompare

[ Source](https://github.com/2blane/IronSQL)[ Packagist](https://packagist.org/packages/anomalous/iron-sql)[ Docs](http://www.meekro.com)[ RSS](/packages/anomalous-iron-sql/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)DependenciesVersions (6)Used By (0)

IronSQL -- PHP database adapter for MySQL Databases. Inspired by MeekroDB.
==========================================================================

[](#ironsql----php-database-adapter-for-mysql-databases-inspired-by-meekrodb)

Learn more:

IronSQL is:

- A PHP MySQL library that lets you **get more done with fewer lines of code**, and **makes SQL injection 100% impossible**.
- There were a few things that [MeekroDB](https://github.com/SergeyTsalkov/meekrodb) didn't contain so I've decided to clone the repository and start my own variation.

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::$host = 'my_host_name';
DB::$user = 'my_database_user';
DB::$password = 'my_database_password';
DB::$dbName = 'my_database_name';

```

### Composer

[](#composer)

Add this to your `composer.json`

```
{
  "require": {
    "anomalous/iron-sql": "*"
  }
}

```

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

```

### 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-httpwwwmeekrocomdocsphp)

How is IronSQL better than PDO?
===============================

[](#how-is-ironsql-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 IronSQL works. Still, if you need database objects, IronSQL 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');

```

### Work with list parameters easily

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

Using MySQL's IN keyword should not be hard. IronSQL 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. IronSQL 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'));

```

### Focus on the goal, not the task

[](#focus-on-the-goal-not-the-task)

Want to do INSERT yourself rather than relying on DB::insert()? It's dead simple. I don't even want to think about how many lines you'd need to pull this off in PDO.

```
// Insert 2 rows at once
  DB::query("INSERT INTO %b %lb VALUES %ll?", 'accounts',
  array('username', 'password', 'last_login_timestamp'),
  array(
    array('Joe', 'joes_password', new DateTime('yesterday')),
    array('Frank', 'franks_password', new DateTime('last Monday'))
  )
);

```

### Nested transactions

[](#nested-transactions-1)

MySQL's SAVEPOINT commands lets you create nested transactions, but only if you keep track of SAVEPOINT ids yourself. IronSQL 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 error and success handlers

[](#flexible-error-and-success-handlers)

Set your own custom function run on errors, or on every query that succeeds. You can easily have separate error handling behavior for the dev and live versions of your application. Want to count up all your queries and their runtime? Just add a new success handler.

### More about IronSQL's design philosophy:

[](#more-about-ironsqls-design-philosophy-httpwwwmeekrocombeliefsphp)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 94.8% 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 ~548 days

Total

5

Last Release

2574d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d3326638f6d62954a68c0d7b05cb221ff7a8f01600353e6b9db2b59d59510dd?d=identicon)[Anomalous](/maintainers/Anomalous)

---

Top Contributors

[![SergeyTsalkov](https://avatars.githubusercontent.com/u/3589642?v=4)](https://github.com/SergeyTsalkov "SergeyTsalkov (110 commits)")[![2blane](https://avatars.githubusercontent.com/u/25189660?v=4)](https://github.com/2blane "2blane (5 commits)")[![bcash](https://avatars.githubusercontent.com/u/570976?v=4)](https://github.com/bcash "bcash (1 commits)")

---

Tags

phpdatabasemysqlpdoadaptermysqli

### Embed Badge

![Health badge](/badges/anomalous-iron-sql/health.svg)

```
[![Health](https://phpackages.com/badges/anomalous-iron-sql/health.svg)](https://phpackages.com/packages/anomalous-iron-sql)
```

###  Alternatives

[sergeytsalkov/meekrodb

The Simple PHP/MySQL Library

340402.6k12](/packages/sergeytsalkov-meekrodb)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k23.1k](/packages/clouddueling-mysqldump-php)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11712.4k](/packages/stefangabos-zebra-database)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1815.7k12](/packages/popphp-pop-db)[riverside/php-orm

PHP ORM micro-library and query builder

111.3k](/packages/riverside-php-orm)

PHPackages © 2026

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