Skip to content

Installation

Muhammet Şafak edited this page May 24, 2026 · 1 revision

Installation

Requirements

  • PHP 8.1 or later — older versions are not supported. The 4.x line technically declared >= 8.0 but its transitive dependencies refused to install on PHP 8.0, so 8.1 is now the floor.
  • ext-pdo — always required.
  • A PDO driver matching your target database — one of:
    • ext-pdo_mysql (MySQL / MariaDB)
    • ext-pdo_pgsql (PostgreSQL)
    • ext-pdo_sqlite (SQLite)
    • any other PDO driver PHP ships (pdo_oci, pdo_sqlsrv, …)

Install via Composer

composer require initphp/database

To install a specific major version:

composer require initphp/database:^5.0

Verify the installation

A two-line smoke test:

<?phprequire__DIR__ . '/vendor/autoload.php';
$db = newInitPHP\Database\Database([
'driver' => 'sqlite',
'database' => ':memory:',
'charset' => '',
]);
$db->getPDO()->exec('CREATE TABLE ping (id INTEGER)');
$db->create('ping', ['id' => 1]);
var_dump($db->select('*')->from('ping')->read()->asAssoc()->rows());

If you see one row come back, you are good to go.

Where things live

After install the package exposes four entry points:

ClassUse case
InitPHP\Database\DBStatic facade — bootstrap once with DB::createImmutable([...]) and call DB::select(...) from anywhere.
InitPHP\Database\DatabaseDirect instantiation — when you want to own the lifecycle yourself, e.g. multiple connections.
InitPHP\Database\ModelSubclass it to bind one table; pairs with Entity.
InitPHP\Database\EntitySubclass it for typed row objects with accessor / mutator hooks.
InitPHP\Database\Utils\Datatables\DatatablesServer-side DataTables.js helper.

Optional development tooling

The package ships its own CI pipeline; if you fork or contribute, install the dev dependencies:

composer install
composer qa # phpcs + phpstan + phpunit
composer cs-fix # auto-format
ToolConfig file
PHPUnitphpunit.xml
PHPStan (level 6)phpstan.neon.dist
PHP_CodeSniffer (PSR-12)phpcs.xml.dist

Next

Clone this wiki locally