Skip to content

kirameki-php/database

Repository files navigation

Database library for PHP

Test codecov GitHub

Prerequisites

  • PHP 8.3+

Installation

composer require kirameki/database

Isolation level

Kirameki will set the isolation level to SERIALIZABLE for all transactions. Lower isolation level is risky and is not worth the small gain in performance for most apps. You can change the isolation level by passing IsolationLevel to a transaction(...).

SQL Database Nuances

Session Level Timeout

Database Supported Description Query
SQLite No option exists.
PostgreSQL Works. (Docs) SET statement_timeout={milliseconds}
MySQL Only works for SELECT. (Docs) SET SESSION max_execution_time={milliseconds}
MariaDB Works. (Docs) SET max_statement_time={seconds}

Isolation Level Changes Per Transaction

Database Supported Description Query
SQLite Only supports read_uncommitted per connection via PRAGMA.
PostgreSQL Works. Must call within the open transaction. (Docs) SET TRANSACTION {mode}
MySQL Works. Must call before BEGIN. (Docs) SET TRANSACTION ISOLATION LEVEL {mode}
MariaDB Same as MySQL (Docs) Same as MySQL

Upsert

Database Supported Description Query
SQLite Works. (Docs) INSERT INTO … ON CONFLICT … DO UPDATE SET…
PostgreSQL Works. (Docs) INSERT INTO … ON CONFLICT … DO UPDATE SET…
MySQL Does not work as expected on tables with multiple unique indexes.
Use with caution. Read the docs carefully. (Docs)
INSERT INTO … ON DUPLICATE KEY UPDATE …
MariaDB Same as MySQL (Docs) Same as MySQL

Affected Row Count

SELECT statements usually return 0 when calling QueryResult::getAffectedRowCount(), but when you run a SELECT statement using RawStatement, the method will give different results depending on the database you use. This is stated in the PHP PDO documentation.

For example, running the following statement will return different results for different databases.

Query:

SELECT 1 as a;
Database Result
SQLite 0
MySQL 1

License

This is an open-sourced software licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published