Advertisement
Guest User

PHP Connection Class

a guest
Apr 10th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. class Connection{
  3.  
  4.     private $dbhost;
  5.     private $dbname;
  6.     private $dbuser;
  7.     private $dbpass;
  8.     private $conn;
  9.     private $result;
  10.    
  11.     function __construct(){
  12.         $this->dbhost = 'localhost';
  13.         $this->dbname = '_database';
  14.         $this->dbuser = '_admin';
  15.         $this->dbpass = 'rawrMyGameDevBitches'; //not really
  16.         print( DEBUG ? "" : "Connection object initalised\n<br />\n");
  17.     }
  18.      
  19.     function connect(){
  20.    
  21.         $this->conn = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die('Could not connect to MySQL server.');
  22.         print( DEBUG ? "" : "MySQL connection successful\n<br />\n");
  23.        
  24.         mysql_select_db($this->dbname, $this->conn) or die('Could not select database.');
  25.         print( DEBUG ? "" : "MySQL database ($this->dbname) selected \n<br />\n");
  26.    
  27.     }
  28.  
  29.     function runQuery($query){
  30.         if ($query == "") {
  31.             die("You need to provide a query.");
  32.         }
  33.         $this->result = mysql_query($query, $this->conn);
  34.     }
  35.      
  36.     function getResult(){
  37.         print(DEBUG ? "" : "Results of query: $this->result");
  38.         return $this->result;
  39.     }
  40.  
  41.     function freeResult(){
  42.         print(DEBUG ? "" : "Freeing result");
  43.         mysql_free_result($this->result);
  44.     }
  45.  
  46.     function close(){
  47.         mysql_close($this->conn);
  48.     }
  49. }  
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement