Posted By

tylerhall on 11/30/-1


Tagged

mysql database wrapper


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

jonbaer
Fixe
jkochis
shamrog12
blakeb
vali29
bioascii
fackz
nb109
umang_nine
dantreacy


MySQL Database Wrapper


 / Published in: PHP
 

  1. <?PHP
  2. class Database
  3. {
  4. var $db;
  5. var $result;
  6. var $lastQuery;
  7. var $numQueries = 0;
  8. var $error;
  9. var $showErrors = true;
  10.  
  11. function Database($host, $user, $password, $dbname)
  12. {
  13. $this->db = mysql_connect($host, $user, $password) or die(mysql_error());
  14. mysql_select_db($dbname, $this->db) or die(mysql_error());
  15. }
  16.  
  17. function query($sql)
  18. {
  19. $this->error = "";
  20. $this->lastQuery = $sql;
  21.  
  22. if($this->showErrors)
  23. $this->result = mysql_query($sql, $this->db) or die(mysql_error() . "<br/>--<br/>$sql");
  24. else
  25. $this->result = mysql_query($sql, $this->db) or ($this->error = mysql_error());
  26.  
  27. $this->numQueries++;
  28. }
  29. }
  30. ?>

Report this snippet  

You need to login to post a comment.