Search by

openrajska / php-oracledb

victorbergamo

A typed API for Oracle Database in PHP

Package info

github.com/openrajska/php-oracledb

pkg:composer/openrajska/php-oracledb

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

dev-main 2026-12-02 17:19 UTC

This package is auto-updated.

Last update: 2026-12-02 17:20:44 UTC


README

A typed API for Oracle Database in PHP, with full PL/SQL fidelity: REF CURSORs, typed OUT and IN OUT binds, Implicit results, Objects and Collections, Array DML with per-row errors, and exact values that never depend on NLS settings. It runs on the oracledb extension, a Rust thin Backend: no Oracle Instant Client, nothing to compile.

A community project, not affiliated with, endorsed by or sponsored by Oracle.

Note

The project is 0.x: the API may break between minor versions. Require a minor version (^0.1) and read the changelog before upgrading.

Requirements

  • PHP 8.4, NTS or ZTS (FPM, CLI, FrankenPHP worker mode or Octane; sync only)

  • Oracle AI Database 26ai

  • The oracledb extension, from openrajska/php-oracledb-ext, on one of the platforms it ships binaries for:

    OS Architectures Notes
    Linux, glibc x86_64, arm64 glibc 2.36 or newer (Debian 12 bookworm and later)
    Linux, musl x86_64, arm64 Alpine, such as the official php:8.4-*-alpine images
    macOS arm64

    There is no binary for Windows, macOS Intel or a glibc older than 2.36 (Ubuntu 22.04, RHEL and Oracle Linux 8 and 9, Amazon Linux 2023). On Windows PIE refuses the package; on macOS Intel it fails when it finds no matching binary; on an older glibc it installs the glibc binary anyway, and PHP may then fail to load it.

Installing

pie install openrajska/php-oracledb-ext   # a pre-built binary; PIE 1.4.0 or newer
composer require openrajska/php-oracledb
php --ri oracledb                         # check it is loaded

PIE never compiles the extension: it downloads the binary for your platform, PHP 8.4 NTS or ZTS. In CI and Docker builds it needs a GitHub token, unzip and --no-build-tools-check; see Installing the extension in CI.

CLI and FPM read different php.ini files: check the extension is enabled for the SAPI that serves your application. Without it, the first Oracle::connect() throws a ConfigurationException that says so. Loading Core's classes and building a ConnectionConfig never need the extension.

Build stages and static analysis. Core requires ext-oracledb, so Composer refuses to install where the extension is not loaded, such as a Docker build stage or a PHPStan job. Tell it the extension comes later:

composer install --ignore-platform-req=ext-oracledb

Upgrading. Core accepts the extension versions its constraint (ext-oracledb: ^0.1) allows, and the extension is always released before the Core release that needs it. Within those versions, upgrade the extension first, then Core. Across a 0.x minor, the new version falls outside that range: Core 0.1 refuses extension 0.2 at connect(), and Composer refuses to install Core 0.1 once extension 0.2 is loaded. Upgrade both together, in the same deploy. An extension outside the range Core accepts makes connect() throw a ConfigurationException naming both versions and what to upgrade.

Quick start

use Rajska\Oracle\Database\ConnectionConfig;
use Rajska\Oracle\Database\Oracle;

$connection = Oracle::connect(new ConnectionConfig(
    dsn: 'db.example.com:1521/FREEPDB1',
    user: 'shop',
    password: getenv('DATABASE_PASSWORD'),
));

connect() takes a Session from a Pool the process keeps for that config, so call it whenever you need a Connection: there is no Pool object to manage.

$customers = $connection->select(
    'select id, name from customers where country = :country order by id',
    ['country' => 'GB'],
);

foreach ($customers as $customer) {
    $name = $customer['NAME'];
}

$count = $connection->select('select count(*) from orders')->value(); // int

$execution = $connection->run(
    'update orders set status = :status where customer_id = :customer',
    ['status' => 'shipped', 'customer' => 1],
);
$updated = $execution->affected();

Outside a transaction every statement commits on its own. Group statements with transaction():

$orderId = $connection->transaction(function (Connection $connection): int {
    $insert = $connection->run(
        'insert into orders (customer_id, total) values (:customer, :total) returning id into :id',
        ['customer' => 1, 'total' => new In\Number('42.00'), 'id' => new Out\Number()],
    );

    return $insert->out('id')->int();
});

Call a stored procedure or function by name:

$total = $connection->function('billing.order_total', ['order_id' => 1])->number();

$execution = $connection->procedure('billing.close_month', [
    'month_start' => new In\Date(new DateTimeImmutable('first day of this month')),
    'closed' => new Out\Number(),
    'orders' => new Out\RefCursor(),
]);
$closed = $execution->out('closed')->int();
$closedOrders = $execution->out('orders')->cursor()->all();

When you are done, close() the Connection, or let it go out of scope: either way its Session goes back to the Pool, and an open transaction rolls back.

Guides

Every PHP example in these docs runs in Core's test suite. Examples assume use imports of the classes they name: Rajska\Oracle\Database\*, the bind namespaces Rajska\Oracle\Database\Binds\In, Out and InOut, and the exceptions in Rajska\Oracle\Database\Exceptions\*.

The vocabulary (Session, Release, Round trip, Call, Implicit result…) is defined in the glossary.

License

MIT or Apache-2.0, at your option.