Posted By

cphoover on 07/02/11


Tagged


Versions (?)

Pass MYSQL by reference


 / Published in: PHP
 

  1. <?php
  2. ini_set('display_errors',1);
  3. error_reporting(E_ALL|E_STRICT);
  4. /*
  5. the first time it should run the external query get data and cache in local sqli then use that data until refreshed
  6. */
  7.  
  8.  
  9.  
  10. require('dbconnect.php');
  11.  
  12.  
  13.  
  14. function getWines($selectString, $distinct = FALSE, $id = NULL, $parentRegion = NULL, $childRegion = NULL, $year = NULL, $rating = NULL){
  15.  
  16. $sql = 'SELECT ' . ($distinct ? DISTINCT : ''). ' ' . mysql_real_escape_string($selectString) .'
  17. FROM `wines` WHERE 1 ';
  18. $sql .= ( $parentRegion ? ' AND `parentRegion` == \'' . mysql_real_escape_string ($parentRegion) . '\'' : '' );
  19. $sql .= ( $id ? ' AND `id` == \'' . mysql_real_escape_string ($id) . '\'' : '' );
  20. $sql .= ( $childRegion ? ' AND `childRegion` == \'' . mysql_real_escape_string ($childRegion) . '\'' : '' );
  21. $sql .= ( $year ? ' AND `year` == \'' . mysql_real_escape_string ($year) . '\'' : '' );
  22. $sql .= ( $rating ? ' AND `rating` == \'' . mysql_real_escape_string ($rating) . '\'' : '' );
  23. $result = mysql_query($sql);
  24. return $result;
  25. }
  26.  
  27.  
  28.  
  29.  
  30. /* --
  31. This function returns a json encoded string from the given object
  32. **/
  33. function parseJSON($data){
  34.  
  35. $JSON = '';
  36.  
  37. while ($row = mysql_fetch_assoc($data)) {
  38. $JSON .= json_encode($row);
  39. }
  40. return $JSON;
  41. }
  42.  
  43.  
  44. echo parseJSON(getWines('*'));
  45.  
  46.  
  47.  
  48. ?>

Report this snippet  

You need to login to post a comment.