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

Report this snippet  

You need to login to post a comment.