Posted By

Piotrek290 on 02/14/10


Tagged

mysql class php simple 02


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Piotrek290
tapdrup


Simple MySql class 0.2


 / Published in: PHP
 

  1. <?
  2. class MySql {
  3. public function query($sql){
  4. $query = @mysql_query($sql, $this->handle) or die(mysql_errno().": ".mysql_error());
  5. return new Result($query);
  6. }
  7.  
  8. public function connect($host, $root, $pass, $data){
  9. $connect = @mysql_connect($host, $root, $pass) or die(mysql_errno().": ".mysql_error());
  10. @mysql_select_db($data, $connect) or die(mysql_errno().": ".mysql_error());
  11. $this->handle = $connect;
  12. return $connect;
  13. }
  14.  
  15. public function put($str){
  16. return new Text($str);
  17. }
  18.  
  19. public function last(){
  20. return @mysql_insert_id($this->handle);
  21. }
  22.  
  23. public function close(){
  24. return @mysql_close($this->handle);
  25. }
  26. }
  27.  
  28. class Result extends MySql{
  29. public function Result($result){
  30. $this->query = $result;
  31. }
  32.  
  33. public function fetch(){
  34. return @mysql_fetch_array($this->query);
  35. }
  36.  
  37. public function is(){
  38. return ($this->query?true:false);
  39. }
  40.  
  41. public function cell($num=0){
  42. $row = @mysql_fetch_row($this->query);
  43. return $row[$num];
  44. }
  45.  
  46. public function num(){
  47. return @mysql_num_rows($this->query);
  48. }
  49.  
  50. public function finish(){
  51. return $this->query;
  52. }
  53. }
  54.  
  55. class Text extends MySql{
  56. public function Text($text){
  57. $this->text = $text;
  58. }
  59.  
  60. public function hash(){
  61. return sha1($this->text);
  62. }
  63.  
  64. public function protect(){
  65. $this->text = htmlspecialchars(stripslashes($this->text));
  66. }
  67.  
  68. return @mysql_real_escape_string($this->text);
  69. }
  70. }
  71. ?>

Report this snippet  

You need to login to post a comment.