Download the PHP package apigopro/slim-database without Composer

On this page you can find all versions of the php package apigopro/slim-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slim-database

apigopro/slim-database

Lazy PDO database connection management for Slim Framework 4, requiring PHP 8.5.

Supports PostgreSQL, MySQL/MariaDB, and Oracle through one consistent API. Built around a dual-credential pattern: separate, distinctly-typed connections for authentication data vs. the rest of the application, so least-privilege database roles are enforced both by Postgres/MySQL/ Oracle GRANTs and by PHP's type system (you can't accidentally inject the wrong connection into the wrong place without it being visible in the constructor signature).

Install

Published on Packagist

Requirements

PostgreSQL

MySQL / MariaDB

Named timezones require a one-time setup step. MySQL doesn't ship with timezone data loaded by default — connecting with DB_TIMEZONE=Europe/Sarajevo (or any named zone) fails with Unknown or incorrect time zone until you load it once per server:

This is a MySQL server-level gotcha, not something this package can work around — it affects any application connecting with a named timezone, not just this one.

Oracle

This is the one that isn't a simple package-manager install — Oracle requires a licensed manual download, no apt/pecl one-liner can fetch it.

  1. Create a free Oracle account and download Instant Client Basic and Instant Client SDK for your platform from Oracle's site (search "Oracle Instant Client downloads" — the exact URL path changes over Oracle's site restructures often enough that it's not worth hardcoding here).

  2. Extract and register the shared libraries:

    (adjust the instantclient_21_1 directory name to whatever version you actually downloaded)

  3. Install build tools and the PECL extensions:

    pdo_oci has, at different points in PHP's history, shipped bundled and also existed as a separate PECL package — check what's actually available for your PHP version before assuming either way:

    Typical PECL install, pointing at your Instant Client directory:

    For non-interactive installs:

  4. Enable the extension(s) in php.ini (or a file under conf.d/):

    Then restart PHP-FPM:

  5. Verify:

I wasn't able to test the Oracle path against a real server while building this package — Oracle's download requires accepting their license through a browser session, which isn't something available in an automated environment. Everything else in this README (PostgreSQL, MySQL, the DSN templating, the connection classes themselves) was verified against real running servers. If you hit something that doesn't match reality during Oracle setup, it's worth double-checking against Oracle's current official docs for your specific Instant Client version.

How the DSN template works

DatabaseCredentials->dns is a printf-style template. AbstractDatabaseConnection builds the final DSN with:

So whatever you put in DB_DNS must have exactly three placeholders, in that order: host, port, name. Examples per driver are in .env.example. If your DSN ever needs a literal % character for some other reason, escape it as %%.

.env setup

Copy .env.example to .env and fill in real values — pick exactly one driver block (Postgres, MySQL, or Oracle) and leave the others commented out. DB_DNS and DB_ENCODING are only meant to be set once; if more than one block is active, later values silently overwrite earlier ones in the same .env file (dotenv doesn't merge repeated keys).

Load it early in your bootstrap, before building your container:

The two-connection pattern

DatabaseConfiguration reads two separate sets of credentials from your env — DB_AUTH_USER/ DB_AUTH_PASSWORD and DB_APP_USER/DB_APP_PASSWORD — sharing the same host/port/database name. The intended setup is two actual database roles with different grants:

AuthDatabaseConnection and AppDatabaseConnection are distinct PHP classes (both extending AbstractDatabaseConnection), not just two instances of the same class — so a constructor type-hint like AuthDatabaseConnection $db is self-documenting, and using the wrong one is a visible mistake in code, on top of the database itself enforcing the real boundary via GRANTs.

Wiring into a DI container (PHP-DI example)

Wiring the closing middleware

Add it first, before any other middleware, so it's the outermost layer — Slim's middleware stack is nested, and the first middleware added is the last to finish on the way out, which is what guarantees the connections close only after the route handler and every other middleware have fully completed:

Usage in an action class

DatabaseCredentials reference

Property Meaning
dns printf-style DSN template — see "How the DSN template works" above.
host Database host.
port Database port.
name Database/service name.
user Connection username.
password Connection password.
timezone Session timezone. Applied via SET TIME ZONE (Postgres), SET time_zone (MySQL), or ALTER SESSION SET TIME_ZONE (Oracle).
encoding Client character encoding. Applied via SET client_encoding (Postgres) or SET NAMES (MySQL). For Oracle, this is instead baked directly into the DSN's ;charset= parameter (see .env.example) rather than set via a session command.
persistent Whether to use PDO::ATTR_PERSISTENT. See "Design notes" below before enabling this on a busy server.
collation MySQL-only: session collation, applied via SET collation_connection. Unused by Postgres/Oracle.
autocommit MySQL/Oracle-only: applied via PDO::ATTR_AUTOCOMMIT. Unused by Postgres (which doesn't expose this as a settable session attribute the same way).

Design notes

Testing

The included tests cover connection lifecycle (get()/close()/isConnected()), the DatabaseConfiguration env-var parsing, and the closing middleware's success/exception paths against a real PostgreSQL instance. MySQL's session-configuration SQL was independently verified against a live MySQL 8.0 server during development (including the named-timezone table dependency noted above). Oracle's SQL/DSN construction was checked for correctness but not run against a live Oracle instance — see "Oracle setup" above for why.

License

MIT.


All versions of slim-database with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ext-pdo Version *
psr/http-message Version ^1.1 || ^2.0
psr/http-server-middleware Version ^1.0
psr/http-server-handler Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package apigopro/slim-database contains the following files

Loading the files please wait ...