Posted By

Piotrek290 on 02/09/10


Tagged

mysql class php simple


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Piotrek290


Simple MySql class


 / Published in: PHP
 

  1. // Author: Dealis
  2. // Site: www.dealis.pl
  3.  
  4.  
  5. class MySql {
  6. public function query($sql){
  7. $query = @mysql_query($sql, $this->handle) or die(mysql_errno().": ".mysql_error());
  8. return new Result($query);
  9. }
  10.  
  11. public function connect($host, $root, $pass, $data){
  12. $connect = @mysql_connect($host, $root, $pass) or die(mysql_errno().": ".mysql_error());
  13. @mysql_select_db($data, $connect) or die(mysql_errno().": ".mysql_error());
  14. $this->handle = $connect;
  15. return $connect;
  16. }
  17.  
  18. public function escape($str){
  19. }
  20.  
  21. return @mysql_real_escape_string($str);
  22. }
  23.  
  24. public function last(){
  25. return @mysql_insert_id($this->handle);
  26. }
  27.  
  28. public function close(){
  29. return @mysql_close($this->handle);
  30. }
  31. }
  32.  
  33. class Result extends MySql{
  34. public function Result($result){
  35. $this->query = $result;
  36. }
  37.  
  38. public function fetch(){
  39. return @mysql_fetch_array($this->query);
  40. }
  41.  
  42. public function is(){
  43. return ($this->query?true:false);
  44. }
  45.  
  46. public function first_cell(){
  47. $row = @mysql_fetch_row($this->query);
  48. return $row[0];
  49. }
  50.  
  51. public function num(){
  52. return @mysql_num_rows($this->query);
  53. }
  54.  
  55. public function finish(){
  56. return $this->query;
  57. }
  58. }

Report this snippet  

You need to login to post a comment.