Advertisement
Guest User

Untitled

a guest
May 14th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2. /**********************************************
  3. ** (c) 2010 by Raw Games. All rights reserved.
  4. ** Connects to MySQL
  5. **********************************************/
  6. class Database
  7. {
  8.     //TODO: Modify these static values
  9.     public static $DB_SERVER = "localhost";
  10.     public static $DB_USER = "root";
  11.     public static $DB_PASSWORD = "password";
  12.     public static $DB_NAME = "webdb";
  13.    
  14.         private $connection;
  15.    
  16.         public $table_pages;
  17.     public $table_general;
  18.     public $table_navigation;
  19.        
  20.     public function __construct() {
  21.         $this->OpenConnection();
  22.     }
  23.        
  24.         public function OpenConnection() {
  25.                 $this->connection = mysql_connect(self::$DB_SERVER,self::$DB_USER,self::$DB_PASSWORD);
  26.                 $this->table_pages = mysql_query("SELECT * FROM pages", $this->connection);
  27.                 $this->table_general = mysql_query("SELECT * FROM general", $this->connection);
  28.                 $this->table_navigation = mysql_query("SELECT * FROM general", $this->connection);
  29.                 if(!$this->connection){
  30.                         die("Unable to connect to MySQL!");
  31.                 } else {
  32.             $selection = mysql_select_db(self::$DB_NAME, $this->connection);
  33.             if(!$selection) {
  34.                 die("Unable to select the table from MySQL.");
  35.             }
  36.         }
  37.         }
  38.        
  39.     public function CloseConnection() {
  40.         if(isset($this->connection)) {
  41.             mysql_close($this->connection);
  42.             unset($this->connection);
  43.         }
  44.     }
  45. }
  46.  
  47. $db = new Database();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement