Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. $servername = "ejemplo.es";
  2. $username = "ramon";
  3. $dbname = "bbdd";
  4. $password = "loquesea";
  5.  
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7. if ($conn->connect_error) {
  8. die("Connection failed: " . $conn->connect_error);
  9. }
  10.  
  11. <?php
  12.  
  13. class Database
  14. {
  15. private $_connection = null;
  16.  
  17. public function __construct($host, $username, $password, $database)
  18. {
  19. // connect to database and store the connection for further use
  20. }
  21.  
  22. public function doThisAndThat()
  23. {
  24. // do some fancy database stuff
  25. }
  26.  
  27. public function __destruct()
  28. {
  29. // important for databases is to disconnect from them
  30. }
  31. }
  32.  
  33. $db = new Database($host, $username, $password, $database);
  34. $db->doThisAndThat();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement