Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. class Database {
  3.     public $hostname;
  4.     public $username;
  5.     public $password;
  6.     public $database;
  7.     public $dblink;
  8.    
  9.     public function connect() {
  10.         $this->dblink = mysql_connect($this->hostname,$this->username,$this->password) or die("Could not connect. ");
  11.         mysql_select_db($this->database, $this->dblink) or die("Could not select database.");
  12.     }
  13. }
  14.  
  15. $db = new Database();
  16.  
  17. $db->hostname = 'localhost';
  18. $db->username = 'root';
  19. $db->password = '1234';
  20. $db->database = 'blog';
  21. $db->connect();
  22.  
  23. if ($db->connect()) {
  24.     print("Connected to $db->hostname!");
  25. }
  26.  
  27. else {
  28.     print("Not connected to $db->hostname!");
  29. }
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement