PHP Classes

PHP PDO DB Connection Controller: Connect to a database configured using a subclass

Recommend this page to a friend!

  Author Author  
Picture of Ujah Chigozie peter
Name: Ujah Chigozie peter <contact>
Classes: 17 packages by
Country: Nigeria Nigeria
Age: 31
All time rank: 240513 in Nigeria Nigeria
Week rank: 38 Up1 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 8x

  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This class can connect to a database configured using a subclass.

It can connect to a given database supported by the PHP PDO extension using classes variables that an application can define using a sub-class of this class.

The class can also perform other database access actions forwarding calls to the PDO object, for instance:

- Preparing queries

- Setting query parameter values

- Executing queries

- Retrieve query results



Php PDO wrapper


Installation is super-easy via Composer:

composer require peterujah/db-controller


Initialize DBController with configuration array

$handler = new \Peterujah\NanoBlock\DBController($configArray);

Or extend \Peterujah\NanoBlock\DBController to set your connection details like below

class Conn extends \Peterujah\NanoBlock\DBController{ 
	public function __construct(bool $development = false){
		$config = array(
			"PORT" => 3306,
			"HOST" => "localhost",
			"VERSION" => "mysql",
			$config["USERNAME"] = "root";
			$config["PASSWORD"] = "";
			$config["NAME"] = "dbname";
			$config["USERNAME"] = "dbusername";
			$config["PASSWORD"] = "dbpass";
			$config["NAME"] = "dbname";
		$this->onDebug = $development;
		$this->config = $config;

Initialize your custom class

$handler = new Conn($_SERVER["HOST_NAME"]=="localhost");

Now run query select, insert, update, delete etc.. using prepare statment

$handler->prepare('SELECT * FROM users WHERE username = :username LIMIT 1');
$handler->bind(':username', "Peter");
$res = $handler->getOne();

Or run query select, insert, update, delete etc.. using query

$handler->query('SELECT * FROM users');
$res = $handler->getAll();

| Options | Description | |-----------------|-------------------------------------------------------------------------------------| | prepare(string) | Call "prepare" with sql query string to prepare query execution | | query(string) | Call "query" width sql query without "bind" and "param" | | bind(param, value, type) | Call "bind" to bind value to the pdo prepare method | | param(param, value, type) | Call "param" to bind parameter to the pdo statment | | execute() | Execute prepare statment | | rowCount() | Get result row count | | getOne() | Get one resault row, this is useful when you set LIMIT 1 | | getAll() | Retrieve all result | | getInt() | Gets integer useful when you select COUNT() | | getAllObject() | Gets result object | | getLastInsertedId() | Gets list inserted id from table | | free() | Free database connection | | dumpDebug() | Dump debug sql query parameter | | errorInfo() | Print PDO prepare statment error when debug is enabled | | error() | Print connection or execution error when debug is enabled | | setDebug(bool) | Sets debug status | | setConfig(array) | Sets connection config array | | conn() | Retrieve DBController Instance useful when you call "setConfig(config)" |

Connection Config array example

     PORT => 3306,
     HOST => "localhost",
     VERSION => "mysql",
     NAME => "dbname",
     USERNAME => "root",
     PASSWORD => ""


  Classes of Ujah Chigozie peter  >  PHP PDO DB Connection Controller  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog (1)  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP PDO DB Connection Controller
Base name: db-controller
Description: Connect to a database configured using a subclass
Version: 1.0.0
PHP version: 5
License: GNU General Public License (GPL)
All time users: 166 users
All time rank: 8819
Week users: 2 users
Week rank: 349 Up
  Groups   Rate classes User ratings   Applications   Files Files  

Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Databases Database management, accessing and searching View top rated classes


What is the best PHP pdo mysql class?
PHP Project using PDO MySQL Class

  Innovation Award  
PHP Programming Innovation award nominee
March 2022
Number 8
PDO is a popular PHP extension that provides several interfaces for classes that can access many types of SQL databases.

Usually, the developer defines a connection to a specific database type using a connection string with a particular syntax.

Many developers prefer to set connection parameters using specific values passing individual parameters because it is more clear to configure each parameter.

This class provides a means to connect to a database using PDO by specifying the connection parameter values using class variables of a sub-class of this class.

Manuel Lemos

  User ratings  
Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

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

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file Config.php Aux. Auxiliary script

Install with Composer Install with Composer - Download Download all files: db-controller.tar.gz
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.