Guest User

conn

a guest
Sep 23rd, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.  
  3.     class DatabaseConnection
  4.     {
  5.         protected $hostname;
  6.         protected $database;
  7.         protected $username;
  8.         protected $password;
  9.  
  10.         /**
  11.          * hostname setzen
  12.          * @param string hostname
  13.          */
  14.         public function setHostname($hostname)
  15.         {
  16.             $this->hostname = $hostname;
  17.         }
  18.          
  19.         /**
  20.          * db setzen
  21.          * @param string database
  22.          */
  23.         public function setDatabase($database)
  24.         {
  25.             $this->database = $database;
  26.         }
  27.          
  28.         /**
  29.          * sets username
  30.          * @param string username
  31.          */
  32.         public function setUsername($username)
  33.         {
  34.             $this->username = $username;
  35.         }
  36.              
  37.         /**
  38.          * sets password
  39.          * @param string password
  40.          */
  41.         public function setPassword($password)
  42.         {
  43.             $this->password = $password;
  44.         }
  45.          
  46.         /**
  47.          * return mysqliobj
  48.          * @return mysqli
  49.          */
  50.         public function getConnection()
  51.         {
  52.             return new mysqli($this->hostname, $this->username, $this->password, $this->database);
  53.             if (!mysqli_connect_errno()) {
  54.                 throw new Exception('Error: ' .mysqli_connect_errno());
  55.             }
  56.         }
  57.     }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment