PHPackages                             ezsql/ezsql - 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. ezsql/ezsql

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

ezsql/ezsql
===========

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

5.1.3(3mo ago)86849.1k↓40.8%280LGPL-3.0-or-laterPHPPHP &gt;7.1CI failing

Since Mar 25Pushed 3mo ago98 watchersCompare

[ Source](https://github.com/ezSQL/ezsql)[ Packagist](https://packagist.org/packages/ezsql/ezsql)[ RSS](/packages/ezsql-ezsql/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (26)Used By (0)

**ezsql**
=========

[](#ezsql)

[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows)[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux)[![macOS](https://github.com/ezSQL/ezsql/workflows/macOS/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AmacOS)[![codecov](https://camo.githubusercontent.com/d0b578e23bdd122e9d7c70073bf076bb09ab0ea18427986935daf22c54f54e9b/68747470733a2f2f636f6465636f762e696f2f67682f657a53514c2f657a53514c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ezSQL/ezSQL)[![Codacy Badge](https://camo.githubusercontent.com/440f040aa02936e10efca18f21fdca3c5d04f9bcef60c203b519c1a38e3f7345/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6161643166366161616161313466363039333365373536313564613930306238)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com&utm_medium=referral&utm_content=ezSQL/ezsql&utm_campaign=Badge_Grade)[![Maintainability](https://camo.githubusercontent.com/5f744c9ec64fe26b32c091530a2c2bae3c2b17340cc766cf505d8e6925071a51/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f36663631303766323565396465376266343237322f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/ezSQL/ezsql/maintainability)[![Total Downloads](https://camo.githubusercontent.com/96df3b39b8eb7c75b7cf586c860226c9751fce8b54bf2987fb7ec0902a194f05/68747470733a2f2f706f7365722e707567782e6f72672f657a73716c2f657a73716c2f646f776e6c6f616473)](https://packagist.org/packages/ezsql/ezsql)

***A class to make it very easy to deal with database connections.****An universal interchangeable **CRUD** system.*

This is [**Version 5**](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**.

Mainly by:

- The use of `namespace` in the `global` functions **ezFunctions.php** file. Usage of the **global** functions will require the user to begin a `.php` file something like:

    ```
    use function ezsql\functions\where;
    // Or
    use function ezsql\functions\{
        getInstance,
        selecting,
        inserting,
    };
    ```
- Class properties that was accessible by magic methods `get/set`, now PSR 1 camelCase.
- Renamed `select` of `ez_mysqli` to `dbSelect`.
- Renamed class method and behavior of `selecting` to `select`.
- `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters:

    - The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned.
    - This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added.
- Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`.
- renamed cleanInput to clean\_string
- renamed createCertificate to create\_certificate
- added global get\_results to return result sets in different formats

[**Version 4**](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3.

[**Version 3**](https://github.com/ezSQL/ezsql/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features.

This library has an `Database` class, an combination of the [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern) pattern with an [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) container hosting. This library now is following many OOP principles, one in which, the methods properties public access has been removed. This library also following PSR-2, PSR-4, PSR-11 conventions, and mostly PSR-1, that's still an work in progress.

- More Todo...

For an full overview see [documentation Wiki](https://github.com/ezSQL/ezsql/wiki/Documentation), which is not completely finish.

Installation
------------

[](#installation)

```
composer require ezsql/ezsql

```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

// **** is one of mysqli, pgsql, sqlsrv, sqlite3, or Pdo.
use ezsql\Database;

$db = Database::initialize('****', [$dsn_path_user, $password, $database, $other_settings], $optional_tag);

// Is same as:
use ezsql\Config;
use ezsql\Database\ez_****;

$settings = new Config('****', [$dsn_path_user, $password, $database, $other_settings]);

$db = new ez_****($settings);
```

This library will assume the developer is using some sort of IDE with intellisense enabled. The comments/doc-block area will hold any missing documentations. For additional examples see **phpunit** tests, The tests are fully functional integration tests, meaning the are live database tests, no mocks.

The following has been added since version 2.1.7.

***General Methods***

```
to_string($arrays, $separation = ',');
clean($string);
create_cache(string $path = null);
secureSetup(string $key = 'certificate.key',
    string $cert = 'certificate.crt',
    string $ca = 'cacert.pem',
    string $path = '.'._DS
);
secureReset();
create_certificate(string $privatekeyFile = certificate.key,
    string $certificateFile = certificate.crt,
    string $signingFile = certificate.csr,
    string $ssl_path = null, array $details = [commonName => localhost]
);

```

***Shortcut Table Methods***

```
create(string $table = null, ...$schemas);// $schemas requires... column()
column(string $column = null, string $type = null, ...$args);
primary(string $primaryName, ...$primaryKeys);
index(string $indexName, ...$indexKeys);
drop(string $table);

```

Example

```
// Creates an database table
create('profile',
    // and with database column name, datatype
    // data types are global CONSTANTS
    // SEQUENCE|AUTO is placeholder tag, to be replaced with the proper SQL drivers auto number sequencer word.
    column('id', INTR, 11, AUTO, PRIMARY), // mysqli
    column('name', VARCHAR, 50, notNULL),
    column('email', CHAR, 25, NULLS),
    column('phone', TINYINT)
);
```

---

```
innerJoin(string $leftTable = null, string $rightTable = null,
    string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

leftJoin(string $leftTable = null, string $rightTable = null,
    string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

rightJoin(string $leftTable = null, string $rightTable = null,
    string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

fullJoin(string $leftTable = null, string $rightTable = null,
    string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

```

---

```
prepareOn(); // When activated will use prepare statements for all shortcut SQL Methods calls.
prepareOff(); // When off shortcut SQL Methods calls will use vendors escape routine instead. This is the default behavior.
```

### Shortcut SQL Methods

[](#shortcut-sql-methods)

- `having(...$having);`
- `groupBy($groupBy);`
- `union(string $table = null, $columnFields = '*', ...$conditions);`
- `unionAll(string $table = null, $columnFields = '*', ...$conditions);`
- `orderBy($orderBy, $order);`
- `limit($numberOf, $offset = null)`
- `where( ...$whereConditions);`
- `select(string $table = null, $columnFields = '*', ...$conditions);`
- `create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`
- `select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`
- `update(string $table = null, $keyAndValue, ...$whereConditions);`
- `delete(string $table = null, ...$whereConditions);`
- `replace(string $table = null, $keyAndValue);`
- `insert(string $table = null, $keyAndValue);`
- `create(string $table = null, ...$schemas);`
- `drop(string $table = null);`
- `alter(string $table = null, ...$alteringSchema);`
- `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions);`

```
// The variadic ...$whereConditions, and ...$conditions parameters,
//  represent the following global functions.
// They are comparison expressions returning an array with the given arguments,
//  the last arguments of _AND, _OR, _NOT, _andNOT will combine expressions
eq('column', $value, _AND), // combine next expression
neq('column', $value, _OR), // will combine next expression again
ne('column', $value), // the default is _AND so will combine next expression
lt('column', $value)
lte('column', $value)
gt('column', $value)
gte('column', $value)
isNull('column')
isNotNull('column')
like('column', '_%?')
notLike('column', '_%?')
in('column', ...$value)
notIn('column', ...$value)
between('column', $value, $value2)
notBetween('column', $value, $value2)
// The above should be used within the where( ...$whereConditions) clause
// $value will protected by either using escape or prepare statement
```

```
// To allow simple grouping of basic $whereConditions,
// wrap the following around a group of the above comparison
// expressions within the where( ...$whereConditions) clause
grouping( eq(key, value, combiner ), eq(key, value, combiner ) )
// The above will wrap beginning and end grouping in a where statement
// where required to break down your where clause.
```

```
// Note: The usage of this method will require the user/developer to check
// if `query_string` or `param_array` is valid.
//
// This is really an `private` internal method for other shortcut methods,
// it's made public for `class development` usage only.
//
//
// Supply the the whole `query` string, and placing '?' within, with the same number of arguments in an array.
// It will then determine arguments type, execute, and return results.
query_prepared(string $query_string, array $param_array);
// You will need to call this method to get last successful query result.
// It wll return an object array.
queryResult();
```

#### Example for using prepare statements indirectly, with above shortcut SQL methods

[](#example-for-using-prepare-statements-indirectly-with-above-shortcut-sql-methods)

```
// To get all shortcut SQL methods calls to use prepare statements
$db->prepareOn(); // This needs to be called at least once at instance creation

$values = [];
$values['name'] = $user;
$values['email'] = $address;
$values['phone'] = $number;
$db->insert('profile', $values);
$db->insert('profile', ['name' => 'john john', 'email' => 'john@email', 'phone' => 123456]);

// returns result set given the table name, column fields, and ...conditions
$result = $db->select('profile', 'phone', eq('email', $email), between('id', 1, $values));

foreach ($result as $row) {
    echo $row->phone;
}

$result = $db->select('profile', 'name, email',
    // Conditionals can also be called, stacked with other functions like:
    //  innerJoin(), leftJoin(), rightJoin(), fullJoin()
    //      as (leftTable, rightTable, leftColumn, rightColumn, tableAs, equal condition),
    //  where( eq( columns, values, _AND ), like( columns, _d ) ),
    //  groupBy( columns ),
    //  having( between( columns, values1, values2 ) ),
    //  orderBy( columns, desc ),
    //  limit( numberOfRecords, offset ),
    //  union(table, columnFields, conditions),
    //  unionAll(table, columnFields, conditions)
    $db->where( eq('phone', $number, _OR), neq('id', 5) ),
    //  another way: where( array(key, operator, value, combine, combineShifted) );
    //  or as strings double spaced: where( "key  operator  value  combine  combineShifted" );
    $db->orderBy('name'),
    $db->limit(1)
);

foreach ($result as $row) {
    echo $row->name.' '.$row->email;
}

// To get results in `JSON` format
$json = get_results(JSON, $db);
```

#### Example for using prepare statements directly, no shortcut SQL methods used

[](#example-for-using-prepare-statements-directly-no-shortcut-sql-methods-used)

```
$db->query_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? );', [$user, $address, $number]);

$db->query_prepared('SELECT name, email FROM profile WHERE phone = ? OR id != ?', [$number, 5]);
$result = $db->queryResult(); // the last query that has results are stored in `lastResult` protected property
// Or for results in other formats use the global function, will use global database instance if no `$db` supplied
$result = get_results(/* OBJECT|ARRAY_A|ARRAY_N|JSON */, $db); // Defaults to `OBJECT`

foreach ($result as $row) {
    echo $row->name.' '.$row->email;
}
```

Most of shortcut methods have counter **global** *functions* available. They can only be access by beginning your `.php` file like:

```
use function ezsql\functions\functionBelow;
// Or as here, a complete list.
use function ezsql\functions\{
    database,
    mysqlInstance,
    pgsqlInstance,
    mssqlInstance,
    sqliteInstance,
    pdoInstance,
    tagInstance,
    setInstance,
    getInstance,
    clearInstance,
    get_vendor,
///
    to_string,
    clean_string,
    is_traversal,
    sanitize_path,
    create_certificate,
///
    column,
    primary,
    foreign,
    unique,
    index,
    addColumn,
    dropColumn,
    changingColumn,
///
    eq,
    neq,
    ne,
    lt,
    lte,
    gt,
    gte,
    isNull,
    isNotNull,
    like,
    in,
    notLike,
    notIn,
    between,
    notBetween,
///
    where,
    grouping,
    groupBy,
    having,
    orderBy,
    limit,
    innerJoin,
    leftJoin,
    rightJoin,
    fullJoin,
    union,
    unionAll,
///
    creating,
    deleting,
    dropping,
    replacing,
    selecting,
    inserting,
    altering,
    get_results,
    table_setup,
    set_table,
    set_prefix,
    select_into,
    insert_select,
    create_select,
};
```

For the functions **usage/docs** see [ezFunctions.php](https://github.com/ezSQL/ezsql/blob/v5/lib/ezFunctions.php).

For Authors and **[Contributors](https://github.com/ezSQL/ezsql/blob/master/CONTRIBUTORS.md)**
----------------------------------------------------------------------------------------------

[](#for-authors-and-contributors)

Contributing
------------

[](#contributing)

Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :) Create [Github Issues](https://github.com/ezSQL/ezsql/issues) for bugs and new features and comment on the ones you are interested in.

License
-------

[](#license)

**ezsql** is open-sourced software licensed originally under (LGPL-3.0), and the addon parts under (MIT).

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 81.7% 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 ~122 days

Recently: every ~466 days

Total

25

Last Release

93d ago

Major Versions

2.1.7 → 3.0.82018-09-04

3.1.2 → 4.0.02019-03-31

v2.x-dev → 4.0.22019-04-20

v4.x-dev → 5.0.02021-02-16

PHP version history (5 changes)3.0.8PHP &gt;5.6

4.0.0PHP ^7.0

4.0.10PHP ^7.1

4.0.11PHP ^7.1 || ^8

5.1.2PHP &gt;7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1a9d88c23f07f785e0358746ae2384950a6f8dac0c3bd4fbbc910e94f7eb637?d=identicon)[techno-express](/maintainers/techno-express)

---

Top Contributors

[![TheTechsTech](https://avatars.githubusercontent.com/u/29784725?v=4)](https://github.com/TheTechsTech "TheTechsTech (780 commits)")[![jv2222](https://avatars.githubusercontent.com/u/342192?v=4)](https://github.com/jv2222 "jv2222 (55 commits)")[![dpDesignz](https://avatars.githubusercontent.com/u/361972?v=4)](https://github.com/dpDesignz "dpDesignz (29 commits)")[![fawaf](https://avatars.githubusercontent.com/u/639565?v=4)](https://github.com/fawaf "fawaf (23 commits)")[![ozh](https://avatars.githubusercontent.com/u/223647?v=4)](https://github.com/ozh "ozh (17 commits)")[![winkm89](https://avatars.githubusercontent.com/u/9537674?v=4)](https://github.com/winkm89 "winkm89 (5 commits)")[![JohnRDOrazio](https://avatars.githubusercontent.com/u/231298?v=4)](https://github.com/JohnRDOrazio "JohnRDOrazio (5 commits)")[![scottmci](https://avatars.githubusercontent.com/u/129999544?v=4)](https://github.com/scottmci "scottmci (4 commits)")[![mikesalmonuk](https://avatars.githubusercontent.com/u/5956319?v=4)](https://github.com/mikesalmonuk "mikesalmonuk (3 commits)")[![Xymanek](https://avatars.githubusercontent.com/u/2865341?v=4)](https://github.com/Xymanek "Xymanek (3 commits)")[![wninaus](https://avatars.githubusercontent.com/u/6861252?v=4)](https://github.com/wninaus "wninaus (3 commits)")[![yohancreemers](https://avatars.githubusercontent.com/u/4000329?v=4)](https://github.com/yohancreemers "yohancreemers (3 commits)")[![zag2me](https://avatars.githubusercontent.com/u/1050512?v=4)](https://github.com/zag2me "zag2me (2 commits)")[![dannetstudio](https://avatars.githubusercontent.com/u/2724194?v=4)](https://github.com/dannetstudio "dannetstudio (2 commits)")[![hubaishan](https://avatars.githubusercontent.com/u/2285457?v=4)](https://github.com/hubaishan "hubaishan (2 commits)")[![lucanos](https://avatars.githubusercontent.com/u/126774?v=4)](https://github.com/lucanos "lucanos (2 commits)")[![madvik](https://avatars.githubusercontent.com/u/3822529?v=4)](https://github.com/madvik "madvik (2 commits)")[![ricardopadilha](https://avatars.githubusercontent.com/u/1210756?v=4)](https://github.com/ricardopadilha "ricardopadilha (2 commits)")[![rythie](https://avatars.githubusercontent.com/u/290010?v=4)](https://github.com/rythie "rythie (1 commits)")[![SalehObaid](https://avatars.githubusercontent.com/u/3743812?v=4)](https://github.com/SalehObaid "SalehObaid (1 commits)")

---

Tags

cruddbadbalezsqlmysqlmysqlioraclepdopgsqlphpshortcutsqlsqlite3sqlserverabstractiondatabasemysqlsqlitepostgresqlsqlpdosqlservermssqlsqlsrvcrudmysqlisqlite3dba

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jv2222/ezsql

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

86711.6k2](/packages/jv2222-ezsql)[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5014.0M134](/packages/dibi-dibi)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4883.1M39](/packages/aura-sqlquery)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

44243.2k4](/packages/aura-sqlschema)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41256.9k7](/packages/atlas-query)

PHPackages © 2026

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