PHP library for automating MySQL/MariaDb tasks within your project

v0.5.2 2018-07-03 21:29 UTC


DbLib is a PHP library designed to make it easier to work with MySQL/MariaDb databases that your project depends on.

Please note that this project is in initial development and as such, some documentation may be incomplete.

Getting Started

DbLib is intended to be fully compliant with PSR-1, PSR-2, & PSR-4


DbLib works with both MySQL and MariaDb.

To check if the PDO MySQL driver is enabled, run the following command in the CLI or add it to a page in your web root...

phpinfo(); <-- Use with script in webroot.
php -i <-- Use with CLI

and ensure PDO drivers lists MySQL. If it doesn't or you cannot find any mention of PDO in phpinfo(). You may need to recompile PHP using:

./configure --with-pdo-mysql


To add DbLib to your project, run:

composer require geeshoe/dblib

If you prefer to use the development branch of dblib-php, use following line of code in the composer.json file.

composer require geeshoe/dblib dev-develop


DbLib Configuration parameters are set using the Json format.

Copy the included dblibConfig_DIST.json to a secure location outside of your projects web root.

Change the values to reflect your database configuration.

  "dblibConfig" : {
    "hostName" : "",
    "port" : "3306",
    "username" : "myUsername",
    "password" : "SomePassword",
    "database" : "OptionalSeeDocumentation",
    "pdoAttributes" : [

The "database" & "pdoAttributes" param's are not required. If the database is not specified in the config file, you must explicitly declare the database to use in your SQL statements.

I.e. 'SELECT * FROM database.tableName';

PDO Attributes can be set in the config file as demonstrated above. More than one attribute can be set as follows:

"pdoAttributes" : [

Persistent Connections are planned in the future for DbLib, but currently are not supported. Because DbLib does not explicitly close PDO connections, it is possible to extend the DbLib class and override the connect()method to set PDO::ATTR_PERSISTENT => true.


API & usage documentation is soon to come.


Source available at (

For questions, comments, or rant's, drop me a line at

jr (at) geeshoe (dot) com