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(5y ago)01281MITPHPPHP &gt;=7.0CI failing

Since Jun 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ikto/pgi)[ Packagist](https://packagist.org/packages/ikto/pgi)[ RSS](/packages/ikto-pgi/feed)WikiDiscussions dev Synced 4w 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 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

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

1897d 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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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