Advertisement
laurens-wuyts

db_connect.php

May 12th, 2015
5,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. class DB_CONNECT {
  3.  
  4.     // constructor
  5.     function __construct() {
  6.         // connecting to database
  7.         $this->connect();
  8.     }
  9.  
  10.     // destructor
  11.     function __destruct() {
  12.         // closing db connection
  13.         $this->close();
  14.     }
  15.  
  16.     function connect() {
  17.         // import database connection variables
  18.         require_once __DIR__ . '/db_config.php';
  19.  
  20.         // Connecting to mysql database
  21.         $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
  22.  
  23.         // Selecing database
  24.         $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
  25.  
  26.         // returing connection cursor
  27.         return $con;
  28.     }
  29.  
  30.     function close() {
  31.         // closing db connection
  32.         mysql_close();
  33.     }
  34.  
  35. }
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement