PHP Database Connection Class


/ Published in: PHP
Save to your folder(s)

Just a beginning, hoping to refine this ASAP.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /*
  4.  * Author: Alvin Crespo
  5.  * Date: 2/19/2010
  6.  *
  7.  * Database Manager
  8.  *
  9.  * */
  10.  
  11. class dbmanager{
  12.  
  13. private $db_link;
  14. private $hostname = 'localhost';
  15. private $username = 'username';
  16. private $password = 'password';
  17. private $dbname;
  18.  
  19. function __construct($dbname){
  20.  
  21. $this->dbname = $dbname;
  22. $this->db_connect();
  23.  
  24. }
  25.  
  26. function db_connect(){
  27.  
  28. $this->db_link = new mysqli($this->hostname, $this->username, $this->password, $this->dbname);
  29.  
  30. }
  31.  
  32. function db_query($query){
  33.  
  34. $result = $this->db_link->query($query);
  35.  
  36. while($row = $result->fetch_array(MYSQLI_ASSOC)){
  37. $rows[] = $row;
  38. }
  39.  
  40. return $rows;
  41.  
  42. }
  43.  
  44. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.