PHP Classes
elePHPant
Icontem

PHP DBAL Wrapper: Establish database connections with Doctrine DBAL

Recommend this page to a friend!
  Info   View files Documentation   View files View files (49)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-07-15 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 106 All time: 9,139 This week: 135Up
Version License PHP version Categories
dbal-wrapper 1.0.0BSD License5.4Databases
Description Author

This class can establish database connections with Doctrine DBAL.

It takes a given database type and instantiates the Doctrine DBAL using an array of parameters to configure a connection to a database of that type and returns the instantiated database connection object.

Currently the class supports the database types mysql, oracle, postgres, mssql, sqlite, drizzle and sybase.

  Performance   Level  
Name: Cyril Ogana <contact>
Classes: 4 packages by
Country: Kenya Kenya
Age: ???
All time rank: 16443 in Kenya Kenya
Week rank: 81 Up1 in Kenya Kenya Up
Innovation award
Innovation award
Nominee: 2x

 

Details

DB

Description

Light Wrapper around Docrines DBAL to handle management of configuration settings for various database types

Installing

Install application via Composer

require "cymapgt/db": "1.*"

Usage

The DB package is built for building database connection settings for various database types supported by Doctrine DBAL

Overview

  • DB is a singleton, which is common pattern used for database connection classes
  • DB is designed to pick DB connection settings from environment variables, but can also take a parameter of database connection settings
  • All the Public Methods of the DB package are static
  • NB: Storing database parameters in environment variable needs careful considerations Security considerations are needed to ensure that they are only accessible to the web server user. If this method is not viable in your scenario, you may use the alternative method that accepts the DB connect settings as an array.

Getters and Setters

Setting The Database Type

DB::setDbType('mysql');

Replace mysql with either of the following: oracle, mssql, sqlite, sybase, drizzle, postgres

Getting The Database Type of a Connection

DB::getDbType();

Get Database Parameters

DB::getDatabaseParameters();

Return an array of the database parameters stored in the web server / operating system environment. The array is an associative array whose indices vary depending on the database type. Database configuration array keys match the Doctrine DBAL database connection settings listed on the documentation for DBAL (http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html).

An example for MySQL is the array would contain user, password, host, port, dbname, driver, unix_socket and charset indices.

Quality Check on the Configuration Settings

Validating Configuration Settings

DB::validateDbParameters($dbParams);

Accepts an array of the DB parameters. It then does two checks. It ensures that the driver which DBAL will use for the database is actually loaded. It then checks that any of the default settings any of the various databases DBAL can load are present in the array. If any of the two checks fails a cymapgt\Exception\DBException will be thrown.

DB::sanitizeDbParameters($dbParams);

Accepts an array of the DB parameters. Some of the DB connection settings are optional e.g. the charset in mysql. This method discards empty configurations prior to the DB connection being instantiated.

Making DB connection and returning a DBAL instance

Connecting from Environment Settings

//dbObj is an instance of DBAL loading your favourite DB . You can make your queries
$dbObj = DB::connectDb();

Connecting with an Array of config settings

DB::setDbType('mysql');

//define settings in array
$mysqlSettings = array (
 'user' => 'cr7',
 'password' => 'valdebas',
 'host' => 'localhost',
 'port' => '3306',
 'dbname' => 'undecima'
);

//return dbal instance with the mysql dbl loaded
$dbObj = DB::connectDbNew($mysqlSettings);

Closing Database Connections

//Part of resource management and ensuring sensitive information is discarded is destroying resources after use
DB::closeDbConnection();

Testing

DB Tests are provided with the package. SQLITE db is used in the testsuite.

Contribute

  • Email @rhossis or contact via Skype
  • Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  • You will be added as author for contributions ... duh :)

License

BSD 3 CLAUSE

  Files folder image Files  
File Role Description
Files folder imagebuild (1 directory)
Files folder imagedocs (1 directory)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file phpdox.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  build  
File Role Description
Files folder imagephpdox (1 directory)

  Files folder image Files  /  build  /  phpdox  
File Role Description
Files folder imagexml (2 files, 2 directories)

  Files folder image Files  /  build  /  phpdox  /  xml  
File Role Description
Files folder imageclasses (3 files)
Files folder imagetokens (1 file, 1 directory)
  Accessible without login Plain text file index.xml Data Auxiliary data
  Accessible without login Plain text file source.xml Data Auxiliary data

  Files folder image Files  /  build  /  phpdox  /  xml  /  classes  
File Role Description
  Accessible without login Plain text file cymapgt_core_utility_db_DB.xml Data Auxiliary data
  Accessible without login Plain text file cymapgt_Exception_DBException.xml Data Auxiliary data
  Accessible without login Plain text file Exception.xml Data Auxiliary data

  Files folder image Files  /  build  /  phpdox  /  xml  /  tokens  
File Role Description
Files folder imageException (1 file)
  Accessible without login Plain text file DB.php.xml Data Auxiliary data

  Files folder image Files  /  build  /  phpdox  /  xml  /  tokens  /  Exception  
File Role Description
  Accessible without login Plain text file DBException.php.xml Data Auxiliary data

  Files folder image Files  /  docs  
File Role Description
Files folder imagehtml (5 files, 3 directories)

  Files folder image Files  /  docs  /  html  
File Role Description
Files folder imageclasses (3 files, 2 directories)
Files folder imagecss (2 files)
Files folder imagesource (2 files, 1 directory)
  Accessible without login HTML file classes.xhtml Data Auxiliary data
  Accessible without login Plain text file index.xhtml Data Auxiliary data
  Accessible without login Plain text file interfaces.xhtml Data Auxiliary data
  Accessible without login Plain text file namespaces.xhtml Data Auxiliary data
  Accessible without login Plain text file traits.xhtml Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  classes  
File Role Description
Files folder imagecymapgt_core_utility_db_DB (8 files)
Files folder imageException (10 files)
  Accessible without login Plain text file cymapgt_core_utility_db_DB.xhtml Data Auxiliary data
  Accessible without login Plain text file cymapgt_Exception_DBException.xhtml Data Auxiliary data
  Accessible without login Plain text file Exception.xhtml Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  classes  /  cymapgt_core_utility_db_DB  
File Role Description
  Accessible without login Plain text file closeDbConnection.xhtml Data Auxiliary data
  Accessible without login Plain text file connectDb.xhtml Data Auxiliary data
  Accessible without login Plain text file connectDbNew.xhtml Data Auxiliary data
  Accessible without login Plain text file getDatabaseParameters.xhtml Data Auxiliary data
  Accessible without login Plain text file getDbType.xhtml Data Auxiliary data
  Accessible without login Plain text file sanitizeDbParameters.xhtml Data Auxiliary data
  Accessible without login Plain text file setDbType.xhtml Data Auxiliary data
  Accessible without login Plain text file validateDbParameters.xhtml Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  classes  /  Exception  
File Role Description
  Accessible without login Plain text file getCode.xhtml Data Auxiliary data
  Accessible without login Plain text file getFile.xhtml Data Auxiliary data
  Accessible without login Plain text file getLine.xhtml Data Auxiliary data
  Accessible without login Plain text file getMessage.xhtml Data Auxiliary data
  Accessible without login Plain text file getPrevious.xhtml Data Auxiliary data
  Accessible without login Plain text file getTrace.xhtml Data Auxiliary data
  Accessible without login Plain text file getTraceAsString.xhtml Data Auxiliary data
  Accessible without login Plain text file __clone.xhtml Data Auxiliary data
  Accessible without login Plain text file __construct.xhtml Data Auxiliary data
  Accessible without login Plain text file __toString.xhtml Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  css  
File Role Description
  Accessible without login Plain text file source.css Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  source  
File Role Description
Files folder imageException (2 files)
  Accessible without login Plain text file DB.php.xhtml Data Auxiliary data
  Accessible without login Plain text file index.xhtml Data Auxiliary data

  Files folder image Files  /  docs  /  html  /  source  /  Exception  
File Role Description
  Accessible without login Plain text file DBException.php.xhtml Data Auxiliary data
  Accessible without login Plain text file index.xhtml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageException (1 file)
  Plain text file DB.php Class Class source

  Files folder image Files  /  src  /  Exception  
File Role Description
  Plain text file DBException.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagefiles (2 files)
  Accessible without login Plain text file DBTest.php Test Unit test script

  Files folder image Files  /  tests  /  files  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Unit test script
  Accessible without login Plain text file phpunit.xml Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:106
This week:0
All time:9,139
This week:135Up