Overview
This package is not a DB abstraction layer even though it may look similar (and draw some inspiration from projects like Doctrine/DBAL, laminas-db, and PEAR::MDB2). Its goal is to leverage PostgreSQL’s strengths in PHP projects rather than assist with building RDBMS-agnostic applications.
One of such strengths is a rich and extensible data type system, so pg_wrapper allows to
Easily build string representations for query parameters,
Automatically convert query result columns from string representations to native PHP types,
Use provided classes to represent PostgreSQL’s complex types (geometric, ranges, etc.) that do not have native PHP equivalents,
Add custom converters for custom and ad-hoc types.
It is possible to use only the converters from this package with some DBAL, but using the complete package has benefits:
Postgres-specific API, e.g.
executeParams()and prepared statements introspection.
Requirements
pg_wrapper requires at least PHP 8.2 with ctype and json extensions (those are usually installed and enabled by default).
Native pgsql extension (not PDO_pgsql) should be enabled to use classes that access the DB, the extension is not a hard requirement.
Minimum supported PostgreSQL version is 12.
It is highly recommended to use PSR-6 compatible metadata cache in production to prevent possible metadata lookups from database on each page request.
Installation
Require the package with composer:
composer require "sad_spirit/pg_wrapper:^3"