eclipxe/engineworks-dbal

PHP Database Abstraction Layer

v2.3.4 2023-02-16 03:49 UTC

README

Source Code Latest Version Software License Build Status Scrutinizer Coverage Status Total Downloads

I create this library to abstract the interactions with a relational database. At the time it was created the PDO extension did not exist. If possible try to use PDO instead of this library, mostly because prepared statements.

I'm maintaining this library because I have several applications depending on it, and I had shared this to other people, so they can also maintain their own projects.

Installation

To install this library you can use:

composer require eclipxe/engineworks-dbal

Objects

EngineWorks\DBAL\DBAL

Main connection object, has several query methods to get the results just as needed. It also contains sql methods to translate SQL Dialects from different drivers.

EngineWorks\DBAL\Recordset

The Recordset class mimics the main methods of the recordset:

  • Open the recordset using an SQL Statement.
  • Walk the recordset using the current cursor.
  • Access values using the values array, stores original values.
  • Use of magic methods Update and Delete.
  • Convert from/to database types to common types.

Some drivers do not know how to get the primary keys on a query, in that case you can specify the entity to affect and also the primary keys.

Mysql driver support this feature, it will check for primary keys, auto incrementing fields or unique indexes.

EngineWorks\DBAL\Pager

The Pager class uses Recordset to access a limited page of a query, it does not load all the records but only the requested ones

About drivers

This library supports Mysqli, Mssql, Sqlsrv and Sqlite3 drivers, you are free to create your own and (please) share it with me.

Mysqli

  • This is the most tested driver on production.

Sqlsrv

  • This driver uses Microsoft PHP Driver for SQL Server.
  • Result does not know the entity or primary keys of the query. Use overrideEntity and overrideKeys when create a Recordset for update or delete.

Sqlite3

  • Result does not know the entity or primary keys of the query. Use overrideEntity and overrideKeys when create a Recordset for update or delete.
  • When a result is empty (nothing to fetch) it is not possible to know the type of the fields, this make this driver unstable to update using Recordset.
  • The method SQLite3Result::fetchArray put the cursor in the first position when called after end of list. This behavior has been corrected on Result and fetch returns always false.

Mssql

  • This driver uses PDO dblib, you will need FreeTDS.
  • Result does not know the entity or primary keys of the query. Use overrideEntity and overrideKeys when create a Recordset for update or delete.
  • The function to quote (PDO::quote) fail with multibyte strings, we are using simple replacements of ' to ''
  • This driver is not really compatible with PHP 7, use Sqlsrv instead

Compatibility

This class will be compatible according to PHP Supported versions.

Contributing

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in the files TODO and CHANGELOG.

License

The eclipxe/engineworks-dbal library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information.