×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: ActionScript
Posted by: Shawn Ramsey
Added: May 7, 2014 2:42 AM
Views: 12
Tags: db mysqli
Database Connection
  1. <?php
  2.  
  3. /**
  4.  * Handling database connection
  5.  * This is all pretty self explanitory(sp?)... Connect to db or throw an error
  6.  *
  7.  */
  8. class DbConnect {
  9.  
  10.     private $conn;
  11.  
  12.     function __construct() {
  13.        
  14.     }
  15.  
  16.     /**
  17.      * Establishing database connection
  18.      * @return database connection handler
  19.      */
  20.     function connect() {
  21.         include_once dirname(__FILE__) . '/Config.php';
  22.  
  23.         // Connecting to mysql database
  24.         $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
  25.  
  26.         // Check for database connection error
  27.         if (mysqli_connect_errno()) {
  28.             echo "SHIT... Failed to connect to MySQL: " . mysqli_connect_error();
  29.         }
  30.  
  31.         // returning a connection resource we can work with
  32.         return $this->conn;
  33.     }
  34.  
  35. }
  36.  
  37. ?>
  38.