Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * @DATABASE
  5.  * ~~~~~~~~~~~~
  6.  * @FILE DESCRIPTION: Handles all database related processes
  7.  * @LAST MODIFIED: April 4, 2012
  8.  */
  9.  
  10. class database
  11. {
  12.     protected $dbc;
  13.    
  14.     function __construct($db_host, $db_name, $db_user, $db_password)
  15.     {
  16.         try
  17.         {
  18.             $this->dbc = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_password);
  19.         }
  20.         catch(PDOException $e)
  21.         {
  22.             echo '<b>An error occured while trying to create a database connection: </b>'. $e->getMessage();
  23.         }
  24.     }
  25.    
  26.     /*
  27.      * @METHOD  setPDOAttribute
  28.      * @DESC    Sets a PDO attribute for our dbc object
  29.      */
  30.    
  31.     public function setAttribute($first_param, $second_param)
  32.     {
  33.         try
  34.         {
  35.             $this->dbc->setAttribute($first_param, $second_param);
  36.         }
  37.         catch(PDOException $e)
  38.         {
  39.             echo 'PDOException Error: '. $e->getMessage();
  40.         }
  41.     }
  42.    
  43.     /*
  44.      * @METHOD  processInsertQuery
  45.      * @DESC    use for all queries BESIDES a select query
  46.      */
  47.    
  48.     public function processQuery($query, array $binds, array $assign)
  49.     {
  50.         $query_handle = $this->dbc->prepare($query);
  51.         $i = 0;
  52.         $value = array();
  53.        
  54.         foreach($binds as $bind)
  55.         {
  56.             $query_handle->bindParam($bind, $value[$i]);
  57.             $value[$i] = $assign[$i];
  58.             $i++;
  59.         }
  60.        
  61.         $query_handle->execute();
  62.     }
  63.    
  64.     public function queryFetch($query)
  65.     {
  66.         //FETCH A QUERY
  67.     }
  68.    
  69.     public function insert($query)
  70.     {
  71.         $this->dbc->exec($query);
  72.     }
  73.    
  74.     public function close_connection()
  75.     {
  76.         if($this->dbc != null)
  77.         {
  78.             $this->dbc = null;
  79.         }
  80.     }
  81. }
  82.  
  83. ?>
Add Comment
Please, Sign In to add comment