Advertisement
asadsuman

DataBaseClass

Jan 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <!--DatabaseClass.php---->
  2. <?php
  3. require_once('config.php');//calling config.php
  4. class Database{
  5.  
  6. public $connection;//property
  7.  
  8. //__construct();
  9. public function __construct(){
  10. $this->openDbConnection();
  11. }
  12.  
  13. //method
  14. public function openDbConnection(){
  15. $this->connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
  16. if (mysqli_connect_errno()) {
  17. # code...
  18. die("Database Connection Failed Badly" . mysqli_error());
  19. }else{
  20. echo "DB Connected Successfully.";
  21. }
  22. }
  23. }
  24. //instance of the class
  25. $database = new Database();
  26.  
  27. //calling the Method
  28. //$database->openDbConnection();
  29. /*
  30. *if we call this Method vis Object than Database will be connected
  31. *but we will make the connection automcatic.
  32. *so we will use a __construct() to connect DB Atomatically.
  33. */
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement