PHPackages                             riculum/php-pdo - 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. riculum/php-pdo

ActiveLibrary

riculum/php-pdo
===============

A complete database toolkit written in PHP to handle MySQL statements

v1.0.3(4y ago)0682MITPHPPHP &gt;=7.4.0

Since Apr 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Riculum/PHP-PDO)[ Packagist](https://packagist.org/packages/riculum/php-pdo)[ RSS](/packages/riculum-php-pdo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (2)

PHP-PDO
=======

[](#php-pdo)

A complete database toolkit written in PHP to handle PDO statements

Installation
------------

[](#installation)

Use the package manager [composer](https://getcomposer.org) to install the library

```
composer require riculum/php-pdo
```

Initial setup
-------------

[](#initial-setup)

### Credentials

[](#credentials)

The basic database settings can be set through environment variables. Add a `.env` file in the root of your project. Make sure the `.env` file is added to your `.gitignore` so it is not checked-in the code. By default, the library looks for the following variables:

- DB\_HOST
- DB\_NAME
- DB\_USERNAME
- DB\_PASSWORD

More information how to use environment variables [here](https://github.com/vlucas/phpdotenv)

### Configuration

[](#configuration)

Import vendor/autoload.php and load the `.env` settings

```
require_once 'vendor/autoload.php';

use Database\Core\Database as DB;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
```

Statements
----------

[](#statements)

The `select` statement is used to return an array containing all the result set rows

```
try {
    $user = DB::select('SELECT * FROM my_table WHERE firstname = ?', ['John']);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `single` statement is used to fetch the next row from a result set

```
try {
    $user = DB::single('SELECT * FROM my_table WHERE firstname = ?', ['John']);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `insert` statement is used to insert new records in a table

```
try {
    $id = DB::insert('INSERT INTO my_table (firstname, lastname) VALUES (?,?)', ['John', 'Doe']);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `insertAssoc` statement is used to insert new records in a table using an associative array

```
$data = [
    'firstname' => 'John',
    'lastname' => 'Doe'
];

try {
    $id = DB::insertAssoc('my_table', $data);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `update` statement is used to modify the existing records in a table

```
try {
    DB::update('UPDATE my_table SET firstname = ? WHERE lastname = ?', ['John', 'Doe']);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `updateAssoc` statement is used to update records in a table using an associative array and a where clause

```
$data = [
    'firstname' => 'John',
    'lastname' => 'Doe'
];

$condition = [
    'key' => 'id',
    'operator' => '=',
    'value' => 1
];

try {
    $id = DB::updateAssoc('my_table', $data, $condition);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

The `delete` statement is used to delete existing records in a table

```
try {
    DB::delete('DELETE FROM my_table WHERE firstname = ?', ['John']);
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

Use `statement` for other operations not mentioned

```
try {
    DB::statement('DROP TABLE my_table');
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

### Transactions

[](#transactions)

Transaction are used to run a series of operations within an entity. If an exception is thrown between `beginTransaction` and `commit`, the transaction will automatically be rolled back.

```
$data = [
    'firstname' => 'John',
    'lastname' => 'Doe'
];

try {
    DB::beginTransaction();
    $id = DB::insertAssoc('my_table', $data);
    DB::update('UPDATE my_table SET firstname = ?, lastname = ? WHERE id = ?', ['Jane', 'Doe', $id]);
    DB::commit();
} catch (PDOException $e) {
    echo $e->getMessage();
}
```

Bugreport &amp; Contribution
----------------------------

[](#bugreport--contribution)

If you find a bug, please either create a ticket in github, or initiate a pull request

Versioning
----------

[](#versioning)

We adhere to semantic (major.minor.patch) versioning (). This means that:

- Patch (x.x.patch) versions fix bugs
- Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
- Major (major.x.x) versions introduce radical changes which are not backwards compatible.

In your automation or procedure you can always safely update patch &amp; minor versions without the risk of your application failing.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

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 ~9 days

Total

4

Last Release

1466d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e97ab7f5df25dc6a139dafbc8cc132c1a46edcf555183b39eed94396cef666c2?d=identicon)[Riculum](/maintainers/Riculum)

---

Top Contributors

[![riculum](https://avatars.githubusercontent.com/u/88209361?v=4)](https://github.com/riculum "riculum (9 commits)")

---

Tags

mysqlpdopdo-mysqlphp

### Embed Badge

![Health badge](/badges/riculum-php-pdo/health.svg)

```
[![Health](https://phpackages.com/badges/riculum-php-pdo/health.svg)](https://phpackages.com/packages/riculum-php-pdo)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[bacula-web/bacula-web

The open source web based reporting and monitoring tool for Bacula

1537.5k](/packages/bacula-web-bacula-web)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[doppar/framework

The Doppar Framework

366.7k8](/packages/doppar-framework)[hardcastle/xrpl_php

PHP SDK / Client for the XRP Ledger

129.7k5](/packages/hardcastle-xrpl-php)

PHPackages © 2026

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