PHPackages                             ikto/pgi - 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. ikto/pgi

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

ikto/pgi
========

Simple PostgreSQL OOP interface

v1.0.0(4y ago)01281MITPHPPHP &gt;=7.0CI failing

Since Jun 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ikto/pgi)[ Packagist](https://packagist.org/packages/ikto/pgi)[ RSS](/packages/ikto-pgi/feed)WikiDiscussions dev Synced 3d ago

READMEChangelogDependencies (1)Versions (3)Used By (1)

PgI: Simple PostgreSQL OOP interface
====================================

[](#pgi-simple-postgresql-oop-interface)

[![Build Status](https://camo.githubusercontent.com/459360dd8d4727d47d4bab1f5e3b5df6e0d4458e15175cbc52901eb2549876e8/68747470733a2f2f7472617669732d63692e6f72672f696b746f2f7067692e7376673f6272616e63683d646576)](https://travis-ci.org/ikto/pgi)

Short description
-----------------

[](#short-description)

This library is inspired by [Perl DBI](http://search.cpan.org/~timb/DBI-1.641/) module. It's database dependent (tied to PostgreSQL), but still tries to be simple. As simple as possible.

It's may be a good choice if you don't want to use ORM or similar thing for some reason. With this library you don't need to interact with PHP API directly. It provides exceptions for errors, what makes possible to write code more cleanly rather than direct interaction with PHP API.

But be careful. It won't stop you if you wan't to shoot your leg :).

Features
--------

[](#features)

- Exceptions for database-level errors.
- Nested transactions mechanism (using savepoints).
- Automatic bidirectional data conversion between db and php. For example *timestamp with time zone* is represented as *DateTime*.

Requirements (environment)
--------------------------

[](#requirements-environment)

- PHP 7.0 or higher
- **pgsql** extension

How to use
----------

[](#how-to-use)

Here is a couple of examples.

```
use IKTO/PgI;

// Connecting to the database.
$dbh = PgI::connect('host=127.0.0.1 port=5432 dbname=pgi_test', 'postgres', 'postgres');

// Inserting a row into database table.
if (!$dbh->doQuery('INSERT INTO "message" (name, data) VALUES ($1, $2)', [], ['Welcome!', 'Hello, this is a test!'])) {
    throw new \RuntimeException('Something went wrong');
}

// Updating rows in db.
$count = $dbh->doQuery('UPDATE "record" SET "published" = $1 WHERE "published" = $2 AND "date" < $3', [], [false, true, DateTime::createFromFormat('Y-m-d', '2013-11-21')]);
echo sprintf("We've unpublished %d records", $count);

// Deleting records from db.
$count = $dbh->doQuery('DELETE FROM "record" WHERE "published" = $1', [], [false]);
echo sprintf("We've removed %d unpublished records", $count);

// Selecting the latest record as associative array.
$record = $dbh->selectRowAssoc('SELECT * FROM "record" WHERE "published" = $1 ORDER BY "date" DESC LIMIT 1', [], [true]);

// Selecting the array of available record IDs.
$ids = $dbh->selectColArray('SELECT "id" FROM "record" ORDER BY "id" ASC');

// Getting the next sequence value.
$id = $dbh->getSeqNextValue('record_id_seq');

// Using transactions.
try {
    $dbh->beginWork();

    $id = $dbh->getSeqNextValue('record_id_seq');

    $dbh->doQuery('INSERT INTO "record" (id, date, published) VALUES ($1, NOW(), $2)', [], [$id, false]);

    $dbh->doQuery('INSERT INTO "message" (id_record, name, data) VALUES ($1, $2, $3)', [], [$id, 'Hello', 'This is a test']);

    $dbh->doQuery('UPDATE "record" SET "published" = $1 WHERE "id" = $2', [], [true, $id]);

    $dbh->commit();
} catch (\Exception $e) {
    $dbh->rollback();
}
```

To be continued...

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

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

1805d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5970681?v=4)[ikto](/maintainers/ikto)[@ikto](https://github.com/ikto)

---

Top Contributors

[![mpolishchuck](https://avatars.githubusercontent.com/u/1183791?v=4)](https://github.com/mpolishchuck "mpolishchuck (51 commits)")

---

Tags

dbapipostgresql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ikto-pgi/health.svg)

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

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