Posted By

xoxolatito on 04/14/09


Tagged

select


Versions (?)

Class select from database


 / Published in: PHP
 

URL: none

rammstein plz another disc

  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. }

Report this snippet  

You need to login to post a comment.