Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4.     //Username for the database.
  5.     private $username = "";
  6.     //Password for the database.
  7.     private $password = "";
  8.     //Remote address of the database or localhost if local.
  9.     private $addr = "";
  10.     //The connection link.(if not connect() is null by default).
  11.     private $connection = null;
  12.  
  13.     function __construct($username,$password,$addr)
  14.     {
  15.         $this->username = $username;
  16.         $this->password = $password;
  17.         $this->addr = $addr;
  18.     }
  19.    
  20.     //Establishes a connection to the database.
  21.     function connect()
  22.     {
  23.         if($this->connection != null)
  24.         {
  25.             $con = mysql_connect($this->addr,$this->username,$this->password);
  26.             if($con == false)
  27.             {
  28.                 return false;
  29.             }
  30.             else
  31.             {
  32.                 $this->connection =  $con;
  33.                 return $con;
  34.             }
  35.         }
  36.         else
  37.         {
  38.             return false;
  39.         }
  40.     }
  41.    
  42.    
  43.     //Getters.
  44.     function getUsername()
  45.     {
  46.         return $this->username;
  47.     }
  48.    
  49.     function getPassword()
  50.     {
  51.         return $this->password;
  52.     }
  53.    
  54.     function getAddr()
  55.     {
  56.         return $this->addr;
  57.     }
  58.    
  59.     function getConnection()
  60.     {
  61.         return $this->connection;
  62.     }
  63.  
  64. }
  65.  
  66.  
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement