PHPackages                             tkaratug/titandb-2 - 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. tkaratug/titandb-2

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

tkaratug/titandb-2
==================

A lightweight and efficient SQL query builder library

v2.0.0(8y ago)120MITPHPPHP &gt;=5.4.0

Since Nov 7Pushed 8y ago2 watchersCompare

[ Source](https://github.com/tkaratug/titandb-2)[ Packagist](https://packagist.org/packages/tkaratug/titandb-2)[ Docs](https://github.com/tkaratug/titandb-2)[ RSS](/packages/tkaratug-titandb-2/feed)WikiDiscussions master Synced today

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

TitanDB - 2
===========

[](#titandb---2)

A lightweight and efficient SQL query builder for PHP.

Installation
============

[](#installation)

The recommended way to install the TitanDB v2 Query Builder is through Composer. Run the following command to install it:

```
$ composer require tkaratug/titandb-2
```

Connection
==========

[](#connection)

```
require 'vendor/autoload.php';
use Titan\DB as DB;

$db = DB::init([
	'db_driver'		=> 'mysql',
	'db_host'		=> 'localhost',
	'db_user'		=> 'sample_db_user',
	'db_pass'		=> '',
	'db_name'		=> 'sample_db_name',
	'db_charset'	=> 'utf8',
	'db_collation'	=> 'utf8_general_ci',
	'db_prefix'	 	=> ''
]);
```

Contents
========

[](#contents)

- [SELECT](#select)
- [Fetching Multiple Rows](#getAll)
- [Fetching Single Row](#getRow)
- [WHERE](#where)
- [GROUPING WHERE](#whereGroup)
- [JOIN](#join)
- [ORDER BY &amp; LIMIT](#orderby)
- [GROUP BY](#groupby)
- [HAVING](#having)
- [GROUPING HAVING](#havingGroup)
- [LIKE &amp; NOT LIKE](#like)
- [IN &amp; NOT IN](#in)
- [BETWEEN &amp; NOT BETWEEN](#between)
- [INSERT](#insert)
- [UPDATE](#update)
- [DELETE](#delete)
- [LAST INSERT ID](#lastInsertId)
- [ROW COUNT](#numRows)
- [CUSTOM QUERY](#customQuery)

### select

[](#select)

```
$db->table('test_table')->select('title, content');
// Output: "SELECT title, content FROM test_table"

$db->table('test_table')->select('title as t, content as c');
// Output: "SELECT title as t, content as c FROM test_table"
```

### fetching multiple rows

[](#fetching-multiple-rows)

```
$db->table('test_table')->getAll();
// Output: "SELECT * FROM test_table"

$db->table('test_table')->select('title, content')->getAll();
// Output: "SELECT title, content FROM test_table"
```

### fetching single row

[](#fetching-single-row)

```
$db->table('test_table')->where('status', '=', 1)->getRow();
// Output: "SELECT * FROM test_table WHERE status = 1"

$db->table('test_table')->select('title, content')->where('status', '=', 1)->getRow();
// Output: "SELECT title, content FROM test_table WHERE status = 1"
```

### where

[](#where)

```
$db->table('test_table')
   ->select('title, content')
   ->where('id', '=', 5)
   ->getRow();
// Output: "SELECT title, content FROM test_table WHERE id = 5"

$db->table('test_table')
   ->select('title, content')
   ->where('vote', '>', 20)
   ->where('status', '=', 1)
   ->getAll();
// Output: "SELECT title, content FROM test_table WHERE vote>20 AND status=1"

$db->table('test_table')
   ->select('title, content')
   ->where('vote', '>', 20)
   ->or_where('create_date', '>', date('Y-m-d'))
   ->getAll();
// Output: "SELECT title, content FROM test_table WHERE vote>20 OR create_date>'2017-11-07'"
```

### grouping where

[](#grouping-where)

```
$db->table('test_table')
   ->select('title, content')
   ->where('col_1', '>', 5)
   ->whereGroupStart()
        ->where('col_2', '=', 'val_2')
        ->orWhere('col_2', '=', 'val_3')
   ->whereGroupEnd()
   ->getAll();
// Output: "SELECT title, content FROM test_table WHERE col_1>5 AND (col_2='val_2' OR col_2='val_3')"

$db->table('test_table')
   ->select('title, content')
   ->where('col_1', '>', 5)
   ->whereGroupStart('OR')
        ->where('col_2', '=', 'val_2')
        ->orWhere('col_2', '=', 'val_3')
   ->whereGroupEnd()
   ->getAll();
// Output: "SELECT title, content FROM test_table WHERE col_1>5 OR (col_2='val_2' OR col_2='val_3')"
```

### join

[](#join)

```
$db->table('users as t1')
   ->leftJoin('comments as t2', 't1.user_id=t2.user_id')
   ->select('t1.username, t2.comment')
   ->getAll();
// Output: "SELECT t1.username, t2.comment FROM users as t1 LEFT JOIN comments as t2 ON t1.user_id=t2.user_id"

$db->table('users as t1')
   ->rightJoin('comments as t2', 't1.user_id=t2.user_id')
   ->select('t1.username, t2.comment')
   ->getAll();
// Output: "SELECT t1.username, t2.comment FROM users as t1 RIGHT JOIN comments as t2 ON t1.user_id=t2.user_id"

$db->table('users as t1')
   ->innerJoin('comments as t2', 't1.user_id=t2.user_id')
   ->select('t1.username, t2.comment')
   ->getAll();
// Output: "SELECT t1.username, t2.comment FROM users as t1 INNER JOIN comments as t2 ON t1.user_id=t2.user_id"

$db->table('users as t1')
   ->outerJoin('comments as t2', 't1.user_id=t2.user_id')
   ->select('t1.username, t2.comment')
   ->getAll();
// Output: "SELECT t1.username, t2.comment FROM users as t1 FULL OUTER JOIN comments as t2 ON t1.user_id=t2.user_id"
```

### order by &amp; limit

[](#order-by--limit)

```
$db->table('test_table')->orderBy('id')->getAll();
// Output: "SELECT * FROM test_table ORDER BY id ASC"

$db->table('test_table')->orderBy('id', 'desc')->getAll();
// Output: "SELECT * FROM test_table ORDER BY id DESC"

$db->table('test_table')->orderBy('id', 'desc')->limit(100)->getAll();
// Output: "SELECT * FROM test_table ORDER BY id DESC LIMIT 100"

$db->table('test_table')->order_by('id')->limit(100, 50)->getAll();
// Output: "SELECT * FROM test_table ORDER BY id ASC LIMIT 100, 50"
```

### group by

[](#group-by)

```
$db->table('test_table')->select('book, COUNT(*)')->groupBy('book')->getAll();
// Output: "SELECT book, COUNT(*) FROM test_table GROUP BY book"
```

### having

[](#having)

```
$db->table('test_table')
   ->select('book, COUNT(*)')
   ->groupBy('book')
   ->having('COUNT(*)', '>', 15)
   ->getAll();
// Output: "SELECT book, COUNT(*) FROM test_table GROUP BY book HAVING COUNT(*)>15"

$db->table('test_table')
   ->select('book, COUNT(*)')
   ->groupBy('book')
   ->having('COUNT(*)', '>', 15)
   ->having('COUNT(*)', '', 15)
   ->orHaving('MAX(price)', '', 20)->getAll();
echo $db->numRows();
```

### last executed query

[](#last-executed-query)

```
echo $db->lastQuery();
```

### execute custom query

[](#execute-custom-query)

```
// Fetching single row
$db->customQuery("SELECT * FROM test_table WHERE id=5")->getRow();

// Fetching multiple rows
$db->customQuery("SELECT * FROM test_table")->getAll();

// Insert
$db->customQuery("INSERT INTO test_table SET col_1='val_1', col_2='val_2'");

// Update
$db->customQuery("UPDATE test_table SET col_1='val_1', col_2='val_2' WHERE id=5");

// Delete
$db->customQuery("DELETE FROM test_table WHERE id=5");

// Execute Stored Procedure
$db->customQuery("CALL procedure_1()");
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50dc98a0c75a1aaba61d52bb073e1b0cbdb17f4d5ed4bd1c694c71784b088e16?d=identicon)[tkaratug](/maintainers/tkaratug)

---

Top Contributors

[![tkaratug](https://avatars.githubusercontent.com/u/4394344?v=4)](https://github.com/tkaratug "tkaratug (3 commits)")

---

Tags

phpmysqlsqlpdopgsqlquerybuilder

### Embed Badge

![Health badge](/badges/tkaratug-titandb-2/health.svg)

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

###  Alternatives

[doctrine/dbal

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

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[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)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[atlas/query

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

41249.0k7](/packages/atlas-query)[aura/sqlschema

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

41234.1k4](/packages/aura-sqlschema)

PHPackages © 2026

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