Class select from database


/ Published in: PHP
Save to your folder(s)

rammstein plz another disc


Copy this code and paste it in your HTML
  1. class bd extends conection
  2. {
  3.  
  4. public $table;
  5. public $fields;
  6. public $conection;
  7.  
  8. public function sanitize($param) {
  9.  
  10. return htmlspecialchars($param);
  11.  
  12. }
  13.  
  14. public function select($fields, $table, $where = '') {
  15.  
  16. parent::conexion();
  17. $where = ($where == '') ? '' : ' WHERE ' . $where;
  18. $sql = "SELECT " . implode(',', $fields) . " FROM " . bd::sanitize($table) . $where;
  19. $query = mysql_query($sql);
  20. $select_output = array();
  21. while ($objetos = mysql_fetch_object($query)) {
  22.  
  23. for ($i = 0; $i < sizeof($fields); $i++) {
  24. $select_output[] = $objetos->$fields[$i];
  25. }
  26.  
  27. }
  28.  
  29. return $select_output;
  30. }
  31.  
  32. }

URL: none

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.