loading a fetch query


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



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function loadFetch( $assoc = false, $sql = null )
  4. {
  5.  
  6. unset( $query_fetch );
  7. empty( $query_fetch );
  8.  
  9. $sql = ( is_null($sql) && isset($query_result) ) ? $query_result : $sql;
  10. $fetchType = ( $assoc ) ? MYSQL_ASSOC : MYSQL_NUM;
  11.  
  12. if ( !empty($sql) )
  13. {
  14. while ( $fetch = mysql_fetch_array($sql, $fetchType) )
  15. {
  16. $query_result[] = $fetch;
  17. }
  18.  
  19. if ( !is_array($query_fetch) )
  20. {
  21. throw new Exception( "An error occured while fetching the array" . mysql_error() );
  22. } else {
  23. return $query_result;
  24. }
  25. }
  26.  
  27. }
  28.  
  29. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.