PHPackages                             orinfy/db - 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. orinfy/db

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

orinfy/db
=========

PHP simple query builder

v2.1(5y ago)1151Apache-2.0PHPPHP ^7.1

Since Apr 6Pushed 5y ago2 watchersCompare

[ Source](https://github.com/welllog/DB)[ Packagist](https://packagist.org/packages/orinfy/db)[ RSS](/packages/orinfy-db/feed)WikiDiscussions master Synced 1w ago

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

Welcome to Odb
==============

[](#welcome-to-odb)

The DB class is a simple query builder class in PHP,it based on PDO,and require php version &gt; 7.1.

Usage
-----

[](#usage)

First load your database config

```
\Odb\DB::loadConfig("DBConf.php");
```

database config like this:

```
return [
    'default' => [     // default must exists
        'driver' => 'mysql',   // pgsql(postgresql)
        'host' => '127.0.0.1',
        'port' => '3306',
        'username' => '',
        'password' => '',
        'dbname' => '',
        'charset' => 'utf8',
        'pconnect' => false,
        'time_out' => 3,
        'prefix' => '',
        'throw_exception' => true
    ]
];
```

We use the default "default" connection, so the default configuration is required. Then you have to instantiate the class like this

```
\Odb\DB::connect()->getDBVersion();
```

Switching other connection configurations

```
\Odb\DB::connect('default')->query(...)->get();
```

### Insert values to a table

[](#insert-values-to-a-table)

Insert a record

```
\Odb\DB::table('user')->insert(['name' => 'jack', 'age' => 24]);
```

Insert multiple records

```
\Odb\DB::table('user')->insert([['name' => 'linda', 'age' => 21], ['name' => 'bob', 'age' => 24]]);
```

Get insert record id

```
$id = \Odb\DB::table('user')->insertGetId(['name' => 'ailan', 'age' => 21]);
```

Restrict inserted columns

```
\Odb\DB::table('user')->allow('name', 'age')->insert(['name' => 'jack', 'age' => 24, 'job' => 'programmer']);
```

To see the SQL query that have executed, use the `getSQL()` Method like this:

```
echo \Odb\DB::table('user')->buildInsert(['name' => 'jack', 'age' => 24])->getSQL();
```

Output :

```
'insert into `user` (`name`,`age`) values (?,?)'
```

```
echo \Odb\DB::table('user')->buildInsert(['name' => 'jack', 'age' => 24])->getRSql();
```

Output :

```
'insert into `user` (`name`,`age`) values ('jack', 24)'
```

### Update table values

[](#update-table-values)

```
\Odb\DB::table('user')->where('id', 1)->update(['name' => 'remi']);
```

SQL Query :

```
'update `user` set `name`=? where `id`=?'
```

Increased

```
\Odb\DB::table('scores')->where('id', 10)->increment('score');
\Odb\DB::table('scores')->where('id', '=', 10)->increment('score', 5);
\Odb\DB::table('scores')->where('id', '=', 10)->increment([['score', 1], ['level', 9]]);
```

Decrement

```
\Odb\DB::table('scores')->where('id', '=', 10)->decrement('score');
\Odb\DB::table('scores')->where('id', '=', 10)->decrement('score', 2);
\Odb\DB::table('scores')->where('id', '=', 10)->decrement([['score', 2], ['level', 1]]);
```

#### notice

[](#notice)

**If there is no where，changes will not happened**

### Delete values from table

[](#delete-values-from-table)

```
\Odb\DB::table('logs')->where([['id', '>', 9], ['level', '', 10], ['level', '=', 5]])->orWhere('status', '=', 0)->get();
\Odb\DB::table('user')->where([['id', '>', 10], ['level', '=', 5]])->orWhere('status', '=', 0)
    ->orWhere(function ($query) {
        $query->whereNull('username');
    })->get();
```

where function

```
whereNull('username');
whereNotNull('username');
whereIn('id', [1, 2, 3]);
whereNotIn('id', [1, 2, 3]);
whereBetween('id', [1, 9]);
whereNotBetween('id', [1, 9]);
whereColumn('id', '>', 'parent_id');
where('`username`=? and `age`>?', ['job', 23]);
where('username', '=', 'job')->where('age', '>', 23);
where([['username', '=', 'job'], ['age', '>', 23]]);
whereRaw('`id`>? and `status`=?', [10, 1]);
```

#### use select

[](#use-select)

filter columns

```
\Odb\DB::table('users')->select('id', 'username', 'age')->get();
\Odb\DB::table('users')->select(['id', 'username', 'age'])->get();
\Odb\DB::table('users')->select(['id', 'username', 'age', 'sum(score) as total'])->get();
```

#### use join

[](#use-join)

join function

```
\Odb\DB::table('user as u')->join('article as a', 'u.id', '=', 'a.uid')->select('u.*', 'a.commend')->get();
```

SQL Query :

```
'select  `test_u`.`*`,`test_a`.`commend` from `test_user` as `test_u`  inner join `test_article` as `test_a` on `test_u`.id=`test_a`.uid'
```

you can olso use 'leftJoin' and 'rightJoin' and native sql

```
\Odb\DB::table('user')->leftJoin('role', 'user.role_id', '=', 'role.id')->rightJoin('posts', 'uid', '=', 'user.id');
\Odb\DB::table('user')->join('role', 'test_user.role_id=test_role.id and test_role.status>?', [1]);
```

#### order by,group by...

[](#order-bygroup-by)

```
\Odb\DB::table('user')->orderBy('id', 'desc')->get();
\Odb\DB::table('user')->orderBy('id', 'asc')->get();
\Odb\DB::table('user')->select('count(id) as num')->groupBy('team_id')->having('num', '>', 2)->get();
\Odb\DB::table('user')->select('count(id) as num')->groupBy('team_id')->having('`num`>?', [2])->get();
\Odb\DB::table('user')->limit(2)->get();
\Odb\DB::table('user')->limit(5, 2)->get();
```

### transaction

[](#transaction)

oringfy/DB provide transaction common API

```
\Odb\DB::beginTrans();
\Odb\DB::inTrans();
\Odb\DB::rollBack();
\Odb\DB::commit();
```

### native sql

[](#native-sql)

orinfy/DB also support native sql

```
\Odb\DB::exec('delete from test_user');
\Odb\DB::query('select * from test_user')->get();
\Odb\DB::prepare('select * from test_user where id>?')->execute([10])->get();
\Odb\DB::prepare('update test_user set username=?')->execute(['aiwa'])->rowCount();
\Odb\DB::prepare('insert into test_user (username) values(?)')->execute(['aiwa'])->lastInsertId();
```

###### tips

[](#tips)

If you have any questions please contact

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~97 days

Total

2

Last Release

2135d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/750031e7dd8ea26e9324c4053b7b68d1dea678cc3a6e434b729071918371f07b?d=identicon)[orin](/maintainers/orin)

---

Top Contributors

[![welllog](https://avatars.githubusercontent.com/u/18400816?v=4)](https://github.com/welllog "welllog (14 commits)")

---

Tags

mysqldb

### Embed Badge

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

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

###  Alternatives

[aura/sqlquery

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

4572.9M34](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

135934.5k1](/packages/danielme85-laravel-log-to-db)[colshrapnel/safemysql

A real safe and convenient way to handle MySQL queries.

400103.5k4](/packages/colshrapnel-safemysql)

PHPackages © 2026

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