Posted By

n00ge on 02/02/08


Tagged

select insert php table textmate delete update e


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Juntalis


Table Management Class


 / Published in: PHP
 

This is a start for a table management class. It will select, update, delete, and insert. I'd like to add more functionality on the update and insert functions but it will require some more work (I need to figure out how to split var $3, the columns). Any alterations or additions are welcome.

  1. class $1 extends db {
  2. // SQL Table: ${2:tbl_$1}
  3. // Columns: id,$3
  4.  
  5. function $1 (){
  6.  
  7. }
  8.  
  9. public function get$1(){
  10. db::connect();
  11. \$query = "SELECT id,$3 FROM $2";
  12. \$result = mysql_query(\$query);
  13.  
  14. return \$result;
  15. }
  16.  
  17. public function get$1instance(\$id){
  18. db::connect();
  19. \$query = "SELECT id,$3 FROM $2 WHERE id=" . \$id;
  20. \$result = mysql_query(\$query);
  21.  
  22. return \$result;
  23. }
  24.  
  25. public function insert$1(\$$1details){
  26. db::connect();
  27. \$query = "INSERT INTO $2 ($3) VALUES ('"
  28. \$$1details[$4] . "'" . $0
  29. ")";
  30.  
  31. mysql_query(\$query);
  32.  
  33. return mysql_insert_id();
  34. }
  35.  
  36. public function delete$1(\$id){
  37. db::connect();
  38. \$query = "DELETE FROM $2 WHERE id = " . \$id;
  39.  
  40. mysql_query(\$query);
  41.  
  42. return \$id;
  43. }
  44.  
  45. public function update$1(\$id,\$$1details){
  46. db::connect();
  47. \$query = "UPDATE $2 SET
  48. $4 = '" . \$$1details[$4] . "'
  49. WHERE id = " . \$id;
  50.  
  51. mysql_query(\$query);
  52.  
  53. return \$id;
  54. }
  55. }

Report this snippet  

You need to login to post a comment.