Posted By

Corhol on 07/19/06


Tagged

mysql database class php


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

luman
Eloi
blakeb
christessmer
purpleraison
fael
vali29
devx
pixelhandler
nb109
uilgenstein
prit
clacwebstudio


Database Class


 / Published in: PHP
 

  1. class database {
  2.  
  3. var $host, $name, $user, $pass, $conn, $results;
  4.  
  5. function open ( ) {
  6. $this->conn = mysql_connect( $this->host, $this->user, $this->pass );
  7. mysql_select_db( $this->name, $this->conn ) or die( mysql_error( ) );
  8. return true;
  9. }
  10.  
  11. function close ( ) {
  12. mysql_close ( $this->conn );
  13. return true;
  14. }
  15.  
  16. function connect ( ) {
  17. $this->conn = mysql_pconnect( $this->host, $this->user, $this->pass );
  18. mysql_select_db( $this->name, $this->conn ) or die( mysql_error( ) );
  19. return true;
  20. }
  21.  
  22. function db ( $database ) {
  23. mysql_select_db( $database, $this->conn ) or die( mysql_error( ) );
  24. return true;
  25. }
  26.  
  27. function sql ( $sql ) {
  28. $this->results = mysql_query( $sql ) or die( );
  29. return $this->results;
  30. }
  31.  
  32. function query ( $sql ) {
  33. $this->conn = mysql_connect( $this->host, $this->user, $this->pass );
  34. mysql_select_db( $this->name, $this->conn ) or die( mysql_error( ) );
  35. $this->results = mysql_query( $sql ) or die( );
  36. mysql_close ( $this->conn );
  37. return $this->results;
  38. }
  39.  
  40. }

Report this snippet  

You need to login to post a comment.