PHPackages                             nabeelalihashmi/lightdb - 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. nabeelalihashmi/lightdb

ActiveLibrary

nabeelalihashmi/lightdb
=======================

Lightweight Database Class for PDO

v1.0.0(3y ago)310MITPHP

Since Jun 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/nabeelalihashmi/LightDB)[ Packagist](https://packagist.org/packages/nabeelalihashmi/lightdb)[ RSS](/packages/nabeelalihashmi-lightdb/feed)WikiDiscussions master Synced 4w ago

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

[![LightDB](./docs/header.png)](./docs/header.png)

LightDB
=======

[](#lightdb)

A Fast, Easy, Secure and LightWeight Wrapper for PDO. Supports for easy operation and unique functions like `SET COLUMN = COLUMN + 1`

About Author
------------

[](#about-author)

[Nabeel Ali](https://iconiccodes.com)

Website:

Email:

Features
--------

[](#features)

```
* Fast
* Easy
* Lightweight

```

Installtion
-----------

[](#installtion)

```
composer require nabeelalihashmi/LightDB

```

Basic Usage
-----------

[](#basic-usage)

```
LightDB::setConfig('testdb', 'root', '', 'localhost:3306');

// Insert 1 row
$country1 = [
    'country' => 'Pakistan',
    'capital' => 'Islamabad',
    'population' => 20000000
];
$id = LightDB::insert('south_asian_countries', $country1);

$result = LightDB::findById('south_asian_countries', 1);
$result = LightDB::find('south_asian_countries', 'country like ?', ['b%'], ['country', 'capital', 'population']);

```

### Note

[](#note)

LightDB allows generation of query like

```

with following example

Update table set column = column + 1 where id = 1

```

to have such type of query, put `..` and end of column name in key.

```
$item = LightDB::update('south_asian_countries', 'id = ? ', [1] , ['population..' => 'population + 1']);

```

Methods
-------

[](#methods)

### getInstance

[](#getinstance)

Returns the PDO Object

```
public static function getInstance()

```

### setConfig

[](#setconfig)

- Sets the config for the database
- Args
    - $dbname: Database Name
    - $username: Database Username
    - $password: Database Password
    - $host: Database Host

```
public static function setConfig($db_name, $db_user, $db_pass, $db_host)

```

### query

[](#query)

- This is internally used by functions to run generated query. Can be used by user apps.
- Returns the result of the query in associative array
- Args
    - $query: Query to be executed
    - $params: Parameters to be passed to the query

```
public static function query($query, $args = [])

```

### execute

[](#execute)

\*This is internally used by functions to run generated query. Can be used by user apps. \*Returns PDO Statement

- Args
    - $query: Query to be executed
    - $params: Parameters to be passed to the query

```
public static function execute($query, $args = [])

```

### queryOne

[](#queryone)

\*This is internally used by functions to run generated query. Can be used by user apps. \*Returns the result of the query in associative array

- Args
    - $query: Query to be executed
    - $params: Parameters to be passed to the query

```
public static function queryOne($query, $args = [])

```

### findById

[](#findbyid)

- Returns row matching id
- Args
    - $table: Table Name
    - $id: ID of the row to be found
    - cols = Array of columns to be returned

```
public static function findById($table, $id, $cols = ['*'])

```

### find

[](#find)

- Returns all records matching condition(s)
- Args
    - $table: Table Name
    - $extra\_condition: conditions in form of x = ?
    - $args: Parameters to be passed to the query
    - $cols = Array of columns to be returned

```
public static function find($table, $extra_condition = ' AND 1 == ?', $args = [1], $cols = ['*'])

```

### findOne

[](#findone)

Same as find, but returns one record

```
public static function findOne($table, $extra_condition = ' AND 1 == ?', $args = [1], $cols = ['*'])

```

### insert

[](#insert)

- Requeire the data in assoc array. The keys should be the column names and the values should be the values to be inserted
- Returns the ID of the inserted row
- Args
    - $table: Table Name
    - $data: Data to be inserted in associative array

```
public static function insert($table, $data)

```

### insertAll

[](#insertall)

- Add Multiple rows in one go \*Returns the IDs of the inserted rows
- Args
    - $table: Table Name
    - $data: Data to be inserted in associative array

```
public static function insertAll($table, $data)

```

### update

[](#update)

- Updates the record matching condition.
- Args
    - $table: Table Name
    - $condition: conditions in form of x = ?
    - $condition\_args: Parameters to be passed to the query
    - $data: Data to be updated in associative array

```
public static function update($table, $conditions = "", $condition_args = [], $data = [])

```

### deleteAll

[](#deleteall)

- Deletes all records matching condition(s)
- Reeturns the number of rows deleted
- Args
    - $table: Table Name
    - $condition: conditions in form of x = ?
    - $condition\_args: Parameters to be passed to the query

```
public static function deleteAll($table, $condition = '1 == 1', $args = []) {

```

### deleteById

[](#deletebyid)

- Deletes the record matching id
- Returns the number of rows deleted
- Args
    - $table: Table Name
    - $id: ID of the row to be deleted

```
public static function deleteById($table, $id)

```

### count

[](#count)

- Returns the number of rows matching condition(s)
- Args
    - $table: Table Name
    - $extra\_condition: conditions in form of x = ?
    - $args: Parameters to be passed to the query

```
public static function count($table, $extra_condition = ' AND 1 == ?', $args = [1])

```

### updateOrInsert

[](#updateorinsert)

- If Record exits, updates, else creates a new record.
- Returns number of updated rows
- Args
    - $table: Table Name
    - $condition: conditions in form of x = ?
    - $condition\_args: Parameters to be passed to the query
    - $data: Data to be inserted in associative array

```
public static function updateOrInsert($table, $condition, $condition_args, $data)

```

---

License
-------

[](#license)

LightDB is released under permissive licese with following conditions:

- It cannot be used to create adult apps.
- It cannot be used to gambling apps.
- It cannot be used to create apps having hate speech.

### MIT License

[](#mit-license)

Copyright 2022 Nabeel Ali | IconicCodes.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

1420d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/449341cf2d2c255eeaa52f06da4293fdcf2f407b10984846b6c130418c7b4eab?d=identicon)[nabeelalihashmi](/maintainers/nabeelalihashmi)

---

Top Contributors

[![nabeelalihashmi](https://avatars.githubusercontent.com/u/14184842?v=4)](https://github.com/nabeelalihashmi "nabeelalihashmi (2 commits)")

---

Tags

pdophp-databasephp-database-frameworkphp-mysqlphp-query-builder

### Embed Badge

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

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

PHPackages © 2026

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