Introduction

Simplified DB is a helper PHP class that helps developers perform MySQL operations easily using PDO, Mysqli and Mysql. It has various shorthand methods that reduce code lines, improve readability of your code, improve security, performance & simplify your database operations.

For example, this is the traditional way of running a select query on PDO with prepared statements

 
            <?php
                /*** mysql hostname ***/
                $hostname = 'localhost';
                
                /*** mysql username ***/
                $username = 'username';
                
                /*** mysql password ***/
                $password = 'password';
                
                try {
                
	                /*** connect to database ***/
                    $dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password);
                    
                    /*** echo a message saying we have connected ***/
                    echo 'Connected to database
'; /*** set the error reporting attribute ***/ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*** some variables ***/ $animal_id = 6; $animal_name = 'bruce'; /*** prepare the SQL statement ***/ $stmt = $dbh->prepare("SELECT animal_id,animal_name FROM animals WHERE animal_id = :animal_id AND animal_name = :animal_name"); /*** bind the paramaters ***/ $stmt->bindParam(':animal_id', $animal_id, PDO::PARAM_INT); $stmt->bindParam(':animal_name', $animal_name, PDO::PARAM_STR, 5); /*** execute the prepared statement ***/ $stmt->execute(); /*** fetch the results ***/ $result = $stmt->fetchAll(); /*** loop of the results ***/ foreach($result as $row) { echo $row['animal_id'].'
'; echo $row['animal_name']; } /*** close the database connection ***/ $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } ?>

This is how you will do same thing as above using SimplifiedDB class.

 
             <?php  
                /**** create object of SimplifiedDB class ****/
                $sdb= new SimplifiedDB();
                
                /**** connect to database ****/                
                $sdb->dbConnect("localhost","username","password","dbuser"); 
                
                /**** run select operation and get result (one line code to perform select operation) ****/                
                $result = $sdb->dbSelect("animals",array("animal_id","animal_name"),array("animal_id"=>6,"animal_name"=>"bruce"));
                
                /*** loop of the results ***/
                foreach($result as $row)
                {
              	  echo $row['animal_id'].'
'; echo $row['animal_name']; } ?>

That's it. 2-3 line of code and you are done.

PHP has now three major way of running queries PDO (newest), Mysqli and Mysql (oldest). Developer sometimes needs PDO functionality for new applications developed in PHP, sometimes Mysqli and sometimes they needs to use Mysql extension for older applications. Each of these files contain many useful functions for performing Mysql commands in same way for PDO, Mysql and Mysqli, so you can switch from one way to another just by including respective file. Simplified DB covers most of the operation you needs to perform with different extension PDO,Mysqli and Mysql.

e.g. Insert operation using SimplifiedDB class for PDO, Mysqli and Mysql (Same function defination for each of these 3 extension)

For PDO (include "SimplifiedDBPDO.php" )

 
	          //include(SimplifiedDBPDO.php);
              
      	      $db->dbInsert("user-role-table",array("role_name"=>"Admin","role_description"=>"Manages");
            
For Mysqli (include "SimplifiedDBMysqli.php" )
 
              //include(SimplifiedDBMysqli.php);	
              
      	      $db->dbInsert("user-role-table",array("role_name"=>"Admin","role_description"=>"Manages");
            
For Mysql (include "SimplifiedDBMysql.php" )
 
              //include(SimplifiedDBMysql.php);	            
              
    	       $db->dbInsert("user-role-table",array("role_name"=>"Admin","role_description"=>"Manages");
            

This is how you will write using SimplifiedDB class, just like the same way we have done for PDO and Mysql So using SimplifiedDB class, you can perform mysql operation in any one of 3 major ways PDO, Mysqli and Mysql with same function defination.