PHPackages                             chh/sirel - 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. chh/sirel

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

chh/sirel
=========

Flexible SQL builder which builds an Abstract Syntax Tree of SQL and dumps it.

37681[2 issues](https://github.com/CHH/sirel/issues)PHP

Since Mar 15Pushed 12y ago2 watchersCompare

[ Source](https://github.com/CHH/sirel)[ Packagist](https://packagist.org/packages/chh/sirel)[ RSS](/packages/chh-sirel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Sirel — A Simple Relational Algebra for PHP
===========================================

[](#sirel--a-simple-relational-algebra-for-php)

Sirel is a representation of the SQL Abstract Syntax Tree in PHP.

Sirel aims to be to PHP what [Arel](https://github.com/rails/arel) is for Ruby.

Install
-------

[](#install)

Requirements:

- PHP 5.4
- Optional: `doctrine/dbal` for wider Database support

Install with [Composer](http://getcomposer.org):

```
php composer.phar require 'chh/sirel:1.0.*@dev'

```

Then require `vendor/autoload.php` in your app.

---

Sirel is under **heavy** Development and so the following shortcomings and bugs still have to be ironed out:

- Only tested with **SQLite**, most other DBMS implement a superset of SQLite's SQL, so may also work with MySQL though.
- **No** Generation of DBMS-specific SQL (will likely come as Doctrine DBAL-enabled Visitor)
- Only DML (use [Doctrine DBAL](http://github.com/doctrine/dbal) if you want to run database independent DDL)

Now let's dive into a bird's eye overview of the things that work ;-).

Frequently Asked Questions
--------------------------

[](#frequently-asked-questions)

> How do I protect myself from SQL injection when using Sirel?

I recommend using Prepared Statements. Make sure you mark placeholders as raw SQL with `Sirel::sql()`.

Example using PDO:

```
