PHPackages                             mohamedsaleh077/lno - 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. mohamedsaleh077/lno

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

mohamedsaleh077/lno
===================

Lightweight Advanced and Smart QueryBuilder

014PHP

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/mohamedsaleh077/lno)[ Packagist](https://packagist.org/packages/mohamedsaleh077/lno)[ RSS](/packages/mohamedsaleh077-lno/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

LNO
===

[](#lno)

### LNO Not ORM

[](#lno-not-orm)

Simple Library to turn warp SQL in a smart way. Carries the heavy left from you when you write SQL, without the unlimited complexity in the big Frameworks, just write a human-readable code and boom, you have SQL Query without Syntax errors and talk to your Database with the most secure way and Best practicies. also Lightweight you know?

- on composer:
- [AI Enhanced Documentation](./AI.md)

Why I made LNO?
---------------

[](#why-i-made-lno)

I just wanted to keep using pure PHP until I become good enough in OOP, MVC and most of backend concepts that Framework hide from you. I started wit h a very basic one but I found it useless so I remade it.

NEW Features
------------

[](#new-features)

- Add SubQuery Support.
- Add auto generating for params and order them.
- Add mock files for testing.
- Refactoring code by separating responsibilities.
- Remove UNION.
- Add WITH support to SQL.
- Add PostgreSQL support.

Features
--------

[](#features)

- MySQL support by Default (I will add PostgreSQL later...).
- Auto Order for parts.
- RAW SQL with {} for escaping.
- Multi-Query Support.
- Advanced Nested where conditions.
- UNION Support.
- Issues handler, to protect your db.
- Method Chaining.
- Automatic Backticks.
- Rollback and Transactions for Multiple or single Query.
- Infinity of Joins.
- Insert-Select Support.
- Multiple Values support for Insert.
- Safe DELETE and UPDATE.
- Dependency Injection for DB Driver.

Requirements
------------

[](#requirements)

- PHP 8.2 or later.

Quick Start
-----------

[](#quick-start)

- Just use composer, install the package `mohamedsaleh077/lno`.

```
 $ composer require mohamedsaleh077/lno
```

- import to your code.

```
use mohamedsaleh077/lno/QueryBuilder;
use mohamedsaleh077/lno/MySQL;
use mohamedsaleh077/lno/PostgreSQL;
```

- example for select statement

```
$mysqlDriver = new MySQL();
$postgresDriver = new PostgreSQL();

$sql = new QueryBuilder($mysqlDriver);
$result = $sql->select("users")
                ->where(["id", "=", 2])
                ->callDB()
```

expected result for the SQL: `SELECT * FROM users WHERE id = :p1`.

**Note:** Do not forget to add `.env` in the root directory or in parent directory.

All use cases Explaining
------------------------

[](#all-use-cases-explaining)

### Warnings Enable

[](#warnings-enable)

warnings are enabled by default, to disable it:

```
$sql->enableWarnings(false);
```

### Notes

[](#notes)

- starting another statment like insert after a select or double selects will lead to make a another query and will make two queries when you execute it.
- any conditions like where, join, limit, etc. without select will be ignored.
- writing two where (as an example) in the same query, will lead to override it, join is excluded.
- passing the a non supported formating param will lead to unexcpected behaviours.

### SELECT Part

[](#select-part)

- you need to define the table (Optional, table and its alias)

```
$sql->select("table name");
$sql->select(["tablename", "alias"]); // for aliasing
```

- when you are not defining the columns, it will use \* as default.

```
SELECT * FROM `tablename` AS `alias`
```

- to define columns, make an array for them.

```
$columns = [
    "col1", // `col1`
    "table2.col1", // `table2`.`col1`
    "col2" => "cl", // `col2` AS `cl`
    "table2.col2" => "acl", // `table2`.`col2` AS `acl`
    "table3.*" // `table3`.*
    "{COUNT(*)}" => "c", // COUNT(*) AS `c`
    "{COUNT(col2 > 5)}" // COUNT(col2 > 5)
];
```

- to write a Raw SQL, use `{your sql here}` as {} for escaping them and the Builder won't process them.
- SQL result:

```
SELECT
    `col1`,
    `table2`.`col1`,
    `col2` AS `cl`,
    `table2`.`col2` AS `acl`,
    `table3`.*,
    COUNT(*) AS `c`,
    COUNT(col2 > 5)
FROM `tablename` AS `alias`
```

### WHERE Part

[](#where-part)

- for simple conditions:

```
$sql$t->select("table")->where(["table.col", ">", 34]);
```

result

```
SELECT * FROM `table`
WHERE `table`.`col` > :p2
```

- for Advanced Nested Conditions

```
$t->select("table")
    ->where([
        ["table.col", ">", 15],
        "and", [
        ["num", "not", "null"],
        "or",
        ["table.col", " 5");
```

result

```
SELECT * FROM `users`
HAVING x > 5
```

### ORDER part

[](#order-part)

- pass an array of columns, columns are keys and (asc or desc) as value, for default, do not make it key-value.
- accepts RAW SQL by `{}`

```
$sql->select(["users"])
    ->order(["col1" => "asc", "col2", "col3" => "desc"]);
```

result

```
SELECT * FROM `users`
ORDER BY `col1` ASC, `col2`, col3 DESC
```

### LIMIT Part

[](#limit-part)

- accepts limit and offsset as integers

```
$sql->select(["users"])
    ->limit(1, 15);
```

result

```
SELECT * FROM `users`
LIMIT 1, 15
```

### UNION Part (Deprecated)

[](#union-part-deprecated)

- accepts the word all (optional).
- add it between two SELECTs

```
$sql->select(["users"])
    ->union("all")
    ->select(["uploads"]);
```

result

```
SELECT * FROM `users`
UNION ALL
SELECT * FROM `uploads`
```

### WITH Part

[](#with-part)

- read:

```
$sub = $t->subQuery()
        ->select('test')
        ->where(["id", "=", 12]);

$withs = [
    "cta1" => $sub,
    "cta2" => $sub
];

$t->select("table")
  ->where(["id", "=", 12])
  ->withSQL($withs)
```

result

```
WITH
    cta1 AS ( SELECT * FROM `test` WHERE `id` = :p1 ),
    cta2 AS ( SELECT * FROM `test` WHERE `id` = :p1 )
SELECT * FROM `table`
WHERE `id` = :p2
```

raw SQL
-------

[](#raw-sql)

- if you need to write something is not supported. it will take the order that you called it with

```
$sql->select(["users"])
    ->rawSQL("this is a raw sql")
    ->limit(1, 14);
```

result

```
SELECT * FROM `users`
this is a raw sql
LIMIT 1, 14
```

### INSERT statment

[](#insert-statment)

- you can use it with multiple values or with select.
- insert wont work without either values or select.

```
$t->insert("table_name", ["username", "fullname"])
    ->values(["u1", "f1"])
    ->values(["u2", "f2"])
    ->values(["u3", "f3"])
```

result

```
INSERT INTO `table_name` (`username`, `fullname`)
VALUES
    (:p2, :p3),
    (:p4, :p5),
    (:p6, :p7)
```

or just combine with select.

```
$sql->insert(...)->select(...)->where(...)

```

### UPDATE part

[](#update--part)

- accepts table name and array of columns.
- wont work without where.

```
$t->update("table", ["t"=>"value"])->where(["i", "=", 5]);
```

result

```
UPDATE `table`
SET `t` = :p0
WHERE `i` = :p1
```

### DELETE Part

[](#delete-part)

- accepts table name.
- must included with where.

```
$sql->delete("users")
    ->where(["id", "=", 2]);
```

result

```
DELETE FROM `users`
WHERE `id` = :p2
```

### Running the Query

[](#running-the-query)

- All Params are generated and assigend to values automaticly and beign passed while running the query.
- you just need to define `true` for fetching all results.

```
$result = $sql->callDB(true); // for example
```

- results for each query will be in an array.
- each query will have a result array formed as:

```
$result = [
    "ok" => 0, // success or fail, affected or not. db error will throw exception
    "lastID" => 0, // last inserted ID, in insert statment only
    "edited" => 0, // count of afftected raws
    "len" => 0, // length of results, when $all is true.
    "results" => [] // results for SELECT
];
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance58

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4acf07834f60592ae0f1a7bf7fbada423d521e76d681c2f82051d5c1572b3a4c?d=identicon)[mohamedsaleh077](/maintainers/mohamedsaleh077)

---

Top Contributors

[![mohamedsaleh077](https://avatars.githubusercontent.com/u/211417297?v=4)](https://github.com/mohamedsaleh077 "mohamedsaleh077 (45 commits)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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