PHPackages                             moviet/tuisql - 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. moviet/tuisql

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

moviet/tuisql
=============

A php database query builder library

10PHP

Since Mar 6Pushed 7y agoCompare

[ Source](https://github.com/moviet/tuisql)[ Packagist](https://packagist.org/packages/moviet/tuisql)[ RSS](/packages/moviet-tuisql/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Tuisql - A dynamic query builder
================================

[](#tuisql---a-dynamic-query-builder)

[![Build Status](https://camo.githubusercontent.com/55bc3b89eee7b99dd3db9717854f7c75527bdb8e6884a2de381d82c8bd97a559/68747470733a2f2f7472617669732d63692e6f72672f6d6f766965742f74756973716c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/moviet/tuisql)[![License](https://camo.githubusercontent.com/1e1cb7bae9fc55a01fc5443d26e358dc21c129253bcfa9841db85c4f25aa2ecf/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e7376673f7374796c653d666c61742d737175617265)](http://doge.mit-license.org)[![Usage](https://camo.githubusercontent.com/0b08974388db1eb1c4bdd7154a157aeb6ee7ba89469165e7752420415ab89270/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f75736167652d656173792d6666363962342e737667)](https://github.com/moviet/tuisql)[![Codacy Badge](https://camo.githubusercontent.com/685bb0be5fe974c68cb3fd45172988dca92d3e91da12060cd76ac6607ea944d4/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6665363431356638383034393438383062363963663537346439323438663964)](https://www.codacy.com/app/moviet/tuisql?utm_source=github.com&utm_medium=referral&utm_content=moviet/tuisql&utm_campaign=Badge_Grade)

**Tuisql** is a fast database query builder, scalable and portability, based on PDO (PHP Data Object) as quick prepare statement, build on minimalize source codes with ***richest usage*** that may will help you to make an efficient development and reduce any *complexity* just at the first you have to know how we add security against *sql injection* on the nice *docs* you must read by *carefully* and use with **yaayy**

Already
-------

[](#already)

- [Composer](https://getcomposer.org)

Install
-------

[](#install)

```
composer require "moviet/tuisql"

```

Features
--------

[](#features)

- **Build Connection**
- **Simple C.R.U.D**
- **Various Of Query**
- **Hardcoded Query**
- **Retrieve Query**

Usage
-----

[](#usage)

### Build Connection

[](#build-connection)

- You can simply write database configuration like imho

    SettingDriverHostnamePort NumberDatabase NameUsernamePassword```
    require __DIR__ . '/vendor/autoload.php';

    use Moviet\Base\Tuisql;
    use Moviet\Base\Puppen\Tui;

    $connect = Tui::click(
        ['driver','hostname','port','dbname','username','password']
    );

    // Or simply like this

    $connect = Tui::click(
        ['mysql','localhost','3306','dbname','username','password']
    );
    ```
- For **sqlite** database you can use like simple

    ```
    $connect = Tui::sqlite('folder/folder/folder','mysqlite.db');
    ```

    Path location is your mind on your own directory by using *simply format* on above

### Simple CRUD (Create, Read, Update, Delete)

[](#simple-crud-create-read-update-delete)

- To *insert* a database you can use **Add** just like below

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

    use Moviet\Base\Tuisql;
    use Moviet\Base\Puppen\Tui;

    $build = Tui::click(
        ['mysql','localhost','3306','dbname','username','password']
    );

    $connect = new Tuisql($build);

    $column = ['category','material','color'];

    $values = ['jacket','cotton','brown'];

    $connect->from('table')
            ->column($column)
            ->value($values)
            ->add();
    ```

    `INSERT INTO table (category, material, color) VALUES (:category1, :material2, :color3) `
- Then to *read* a simple database you can use **Run** as simply like this

    ```
    $values = [$varOne, $varTwo, $varNext];

    $connect->select('*')
            ->from('table')
            ->where('id, product')
            ->value($values)
            ->run();
    ```

    `SELECT * FROM table WHERE id=:id1 AND product=:product2`
- We don't want make a hard when *update* database, you can **Fresh** those

    ```
     // use array style
     $connect->select(['table'])
             ->set(['column','column','column','column'])
             ->where(['column'])
             ->value(['work','easy','stay','writable'])
             ->fresh();
    ```
- And last to *delete* database you can express **Del** with yayy

    ```
     // use commas style
     $connect->from('table')
             ->where('column, column')
             ->value([$anyId, $anyVariable])
             ->del();
    ```

    By some different examples on above, you are ***totally free*** to express your styles

### Various Of Query

[](#various-of-query)

- Add single **Limit** Condition

    ```
    $select  = ['column','column','column'];
    $wheres  = ['notes','usage'];

    $values  = ['sweet','easy'];

    $connect->select($select)
            ->from('table')
            ->where($wheres)
            ->limit(10) // value($data)
            ->run();
    ```
- Add **Offset Or Limits** Condition

    ```
    $select  = 'column, column, column';
    $wheres  = 'type, category';

    $values  = ['comma','yippy', 10, 20];  // select($select)
            ->from('table')
            ->where($wheres)
            ->limits('one, two') // value($values)
            ->run();
    ```

    `SELECT column, column, column FROM table WHERE type=:type1 AND category=:category2 LIMIT :one, :two`
- Add **Count** Condition

    ```
    $connect->select('column, column, column')
            ->count('column')
            ->from('table')
            ->where('column')
            ->limits('11, 12') // must be unique :naming
            ->value(['something', 11, 12])
            ->run();
    ```
- Add **Distinct** Condition

    ```
    $connect->distinct('column AS price')
            ->from('table')
            ->where('something')
            ->limit(22)
            ->value(['something'])
            ->run();
    ```
- Add **Group By** Condition

    ```
    $select  = ['column','column','column'];
    $wheres  = ['column','column','column'];

    $values  = ['make','ease','readable'];

    $connect->select($select)
            ->from('table')
            ->where($wheres)
            ->groupBy('hashtable')
            ->value($values)
            ->run();
    ```
- Add **Order By** Condition

    ```
    $select  = ['column','column','column'];
    $wheres  = ['column','column','column'];

    $values  = ['free','styles','whatever'];

    $connect->select($select)
            ->from('table')
            ->where($wheres)
            ->groupBy('column')
            ->OrderBy('date ASC') // limit('15')
            ->value($values)
            ->run();
    ```
- Add **Like** Condition

    ```
    $select  = 'column, column, column';
    $likes   = 'chocolato, coffee';

    $values  = ['delicious','groovy'];

    $connect->select($select)
            ->from('table')
            ->isWhere()  // like($likes)
            ->value($values)
            ->run();
    ```

    The above will add LIKE with **AND** condition, you can put **-&gt;orLike()** to create OR condition
- Add **Having** Condition

    ```
    $connect->select('column, column, column')
            ->from('table')
            ->having('count(column) > :ten') // groupBy('column count(a, b, c)')
            ->value([10]) // run();
    ```
- Add **Between** Condition

    ```
    $select  = 'column, column, column';
    $where   = 'column, column';
    $between = 'column, column'; // select($select)
            ->from('table')
            ->where($where)
            ->between($between)
            ->value($values)
            ->run();
    ```
- Add **OR** with Where Condition

    ```
    $select  = 'column, column, column';
    $where   = 'column, column';

    $values  = ['magnum','doritos'];

    $connect->select($select)
            ->from('table')
            ->or()
            ->where($where)
            ->value($values)
            ->run();
    ```
- Add **Where In** Condition

    ```
    $select  = ['column AS A','column'];
    $whereIn = ['column']; // add where in column
    $addIn   = ['ca, ca, ca, ca']; // add uniques :binding

    $values  = ['cheese','sauce','salt','sugar'];

    $connect->select($select)
            ->from('table')
            ->isWhere()  // whereIn($whereIn, $addIn)
            ->value($values)
            ->run();
    ```
- Add **Not In** Condition

    ```
    $select  = ['column','column'];
    $notIn   = ['column NOT']; // add Not explicitely
    $addIn   = ['id, id, id, id'];

    $values  = ['homies','sweet','home','selfie'];

    $connect->select($select)
            ->from('table')
            ->isWhere()
            ->whereIn($notIn, $addIn)
            ->value($values)
            ->run();
    ```
- **Join** Tables Without Attributes

    ```
    $select  = ['column.a','column.b','column.id as col'];
    $wheres  = ['column.a','column.b'];

    $values  = ['yayy','mooo'];

    $connect->select($select)
            ->from('table.a')
            ->where($wheres)
            ->value($values)
            ->run();
    ```
- **Inner Join** Tables

    ```
    $select  = ['column.a*','column.b*'];
    $table   = ['mytable'];
    $join    = ['inner','column.b'];
    $addOn   = ['column.a=column.id','column.b=column.id'];
    $wheres  = ['column.aid','column.bid']; // from($table)
            ->join($join)
            ->on($addOn)
            ->where($where)
            ->value($values)
            ->run();
    ```

    You can join many table with parameter and add attribute eg. \[join, inner, left, cross, right\]
- **Join** Multi Table With **Where In**

    ```
    $select  = ['column.a*','column.b*'];
    $table   = ['mytable'];
    $join    = ['left','column.b'];
    $addOn   = ['column.a=column.id','column.b=column.id','column.b=column.a'];
    $whereIn = ['column.a']; // from($table)
            ->join($join)
            ->on($addOn)
            ->isWhere()
            ->whereIn($whereIn, $inValue)
            ->orderBy($order)
            ->value($values)
            ->run();
    ```

    **Quotes** :

    > With various examples on above you can express many styles by your self

### Hardcoded Query

[](#hardcoded-query)

- You don't want anybody knows what you need, so you can make a *hardcoded* like this

    ```
    $select  = ['column','column'];
    $table   = ['tableA']
    $join1   = ['join','column.b'];
    $On_1    = ['column.a=column.id','column.a=column.id','column.a=column.e'];
    $join2   = ['inner','column.b'];
    $On_2    = ['column.b=column.id','column.b=column.id','column.b=column.a'];
    $join3   = ['left','column.b'];
    $On_3    = ['column.c=column.id','column.c=column.id','column.c=column.b'];
    $join4   = ['cross','column.c'];
    $On_4    = ['column.d=column.id','column.d=column.id','column.d=column.c'];
    $join5   = ['right','column.c'];
    $On_5    = ['column.e=column.id','column.e=column.id','column.e=column.d'];
    $wereIn1 = ['column.a'];
    $withIn1 = ['a','a','a']; //  a = :ina1,..
    $wereIn2 = ['column.b'];
    $withIn2 = ['b','b','b']; //  b = :inb1,..
    $group   = ['date.a'];
    $order   = ['date.a ASC'];
    $limit   = [20];

    $values  = [1, 2, 3, 4, 8, 16, 24, 32]; // select($select)
            ->from($table)
            ->join($join1)
            ->on($On_1)
            ->join($join2)
            ->on($On_2)
            ->join($join3)
            ->on($On_3)
            ->join($join4)
            ->on($On_4)
            ->join($join5)
            ->on($On_5)
            ->isWhere()
            ->or()
            ->whereIn($wereIn1, $withIn1)
            ->whereIn($wereIn1, $withIn2)
            ->groupBy($group)
            ->orderBy($order)
            ->limit($limit)
            ->value($values)
            ->run();
    ```
- You can create a ***Badass*** query that's still possible and use ***DRAW*** with hardcoded *manually*

    ```
    $colom   = ['columnA','columnB AS Badass'];
    $count   = ['columnD'];
    $table   = ['columnA'];
    $draw1   = ['INNER JOIN column.b AS Bad ON column.id, column.di WHERE columnA.id=:param']; // select($colom)
            ->count($count)
            ->from($table)
            ->draw($draw1)
            ->draw($draw2)
            ->draw($draw3)
            ->join($join1)
            ->on($addOn1)
            ->join($join2)
            ->on($addOn2)
            ->join($join3)
            ->on($addOn3)
            ->where($where)
            ->between($among)
            ->whereIn($whereIn, $withIn)
            ->orLike()
            ->like($likes)
            ->groupBy($groups)
            ->orderBy($orders)
            ->limit($limit)
            ->value($values)
            ->run();
    ```

    **Notes** :

    > You must add uniques **:name** as binding when you get *values* from **outside** to prevent ***sql injection***

    The example on above will produces a hardcoded query like below

    ```
    SELECT columnA, columnB AS Badass,
    COUNT(columnD)
    FROM columnA
    INNER JOIN column.b AS Bad
    ON column.id, column.date
    WHERE columnA.id=:bindparam
    UNION ALL
          (SELECT column.id
           FROM columnC
           LEFT JOIN column.b
           ON column.b=column.id, column.b=column.id, column.b=column.a
           CROSS JOIN column.c
           ON column.c=column.id, column.c=column.id, column.c=column.a
           RIGHT JOIN column.d
           ON column.d=column.id, column.d=column.id, column.d=column.a
           WHERE column.a=:columna1 AND column.b=:columnb2 AND column.c=:columnc3
           AND a.date BETWEEN :bdate AND b.date BETWEEN :bdate
           AND column.a IN(:inid1, :inid2, :inid3)
           AND column.b LIKE :columnb1 OR column.c LIKE :columnc2
           GROUP BY columnA.date, columnB.date, columnC.date
           ORDER BY column.a ASC, column.b ASC, column.c ASC
           LIMIT :hundred)
    ```

### Joins

[](#joins)

AttributesValuesjoinJOINinnerINNER JOINleftLEFT JOINrightRIGHT JOINcrossCROSSS JOIN### Retrieve Query

[](#retrieve-query)

- You can retrieve a *single row* from **Tuisql** as simply as below

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

    use Moviet\Base\Tuisql;
    use Moviet\Base\Puppen\Tui;
    use Moviet\Base\Fetchs\Rtui;

    $database = Tui::click(
        ['mysql','localhost','3306','dbname','username','password']
    );

    $connect = new Tuisql($database);

    $column = ['myid','type','color'];
    $values = [123456];

    $query  = $connect->select($column)
                      ->from('house')
                      ->where('id')
                      ->value($values)
                      ->run();

    $getRow = Rtui::oneRow($query);

    $myid   = $getRow['myid'];
    $type   = $getRow['type'];
    $color  = $getRow['color'];

    $direct = Rtui::notFound($getRow, '404.shtml'); // Direct url eg. url/404.shtml
    ```
- And to retrieve *more data* you can use like this

    ```
    $database = Tui::click(
        ['mysql','localhost','3306','dbname','username','password']
    );

    $connect = new Tuisql($database);

    $column = ['code','shoes','color'];
    $values = [123456];

    $query  = $connect->select($column)
                      ->from('house')
                      ->where('code')
                      ->value($values)
                      ->run();

    $allRow = Rtui::allRow($query); // Equivalent like fetchAll

    foreach ($allRow as $row => $all) {

        $code   = $all['code'];
        $shoes  = $all['shoes'];
        $color  = $all['color'];
    }

    $direct = Rtui::notFound($allRow, '404.shtml'); // Direct url eg. url/404.shtml
    ```
- Retrieve *one column* of query

    ```
    $allRow = Rtui::oneColumn($query);
    ```
- Retrieve *Row Count* of query

    ```
    $allRow = Rtui::count($query);
    ```
- Retrieve *Row Num* of query

    ```
    $allRow = Rtui::oneNum($query);
    ```
- Retrieve *Row Lazy* of query

    ```
    $allRow = Rtui::oneLazy($query);
    ```
- Retrieve *Row Object* of query

    ```
    $allRow = Rtui::allObj($query);
    ```

License
-------

[](#license)

`Moviet/tuisql` is released under the MIT public license.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

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/ed530423003a96fcde2086e595a1709f742c1ea47e8aa1315d5751470314b07a?d=identicon)[Moviet](/maintainers/Moviet)

---

Top Contributors

[![moviet](https://avatars.githubusercontent.com/u/45540985?v=4)](https://github.com/moviet "moviet (12 commits)")

---

Tags

databasedatabase-adapterdatabase-handlerpdoquery-builder

### Embed Badge

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

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

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