php mysql/mysqli fetch array


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



Copy this code and paste it in your HTML
  1. function sqlFetchArray( $query, $type='MYSQL_ASSOC' )
  2. {
  3. if( in_array( 'mysql', $GLOBALS[ 'loaded_extensions' ] ) )
  4. {
  5. switch( $type )
  6. {
  7. case 'MYSQL_NUM':
  8. return @mysql_fetch_array( $query, MYSQL_NUM );
  9. break;
  10. case 'MYSQL_ASSOC':
  11. return @mysql_fetch_array( $query, MYSQL_ASSOC );
  12. break;
  13. case 'MYSQL_BOTH':
  14. return @mysql_fetch_array( $query, MYSQL_BOTH );
  15. break;
  16. }
  17. }
  18. elseif( in_array( 'mysqli', $GLOBALS[ 'loaded_extensions' ] ) )
  19. {
  20. switch( $type )
  21. {
  22. case 'MYSQL_NUM':
  23. return @mysqli_fetch_array( $query, MYSQLI_NUM );
  24. break;
  25. case 'MYSQL_ASSOC':
  26. return @mysqli_fetch_array( $query, MYSQLI_ASSOC );
  27. break;
  28. case 'MYSQL_BOTH':
  29. return @mysqli_fetch_array( $query, MYSQLI_BOTH );
  30. break;
  31. }
  32. }
  33. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.