Posted By

alvincrespo on 02/19/10


Tagged

database class php connection


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

nerdfiles
dantreacy


PHP Database Connection Class


 / Published in: PHP
 

Just a beginning, hoping to refine this ASAP.

  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
Posted By: azs on February 18, 2012

"Call to a member function fetch_array() on a non-object" getting this error can you help.

You need to login to post a comment.