php mysql/mysqli query


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



Copy this code and paste it in your HTML
  1. function sqlQuery( $sql )
  2. {
  3. if( in_array( 'mysql', $GLOBALS[ 'loaded_extensions' ] ) )
  4. {
  5. $query = mysql_query( $sql ) or die(
  6. "<pre><font color=\"red\"><b>Invalid SQL:</b>\n\n("
  7. . ' ) '
  8. . "\n\n"
  9. . "<b>Query:</b>\n"
  10. . eregi_replace( "\t", ' ', $sql )
  11. . '</font></pre>' );
  12. }
  13. elseif( in_array( 'mysqli', $GLOBALS[ 'loaded_extensions' ] ) )
  14. {
  15. $query = mysqli_query( $GLOBALS[ 'dbHandle' ], $sql ) or die(
  16. "<pre><font color=\"red\"><b>Invalid SQL:</b>\n\n("
  17. . mysqli_errno( $GLOBALS[ 'dbHandle' ] )
  18. . ' ) '
  19. . mysqli_error( $GLOBALS[ 'dbHandle' ] )
  20. . "\n\n"
  21. . "<b>Query:</b>\n"
  22. . eregi_replace( "\t", ' ', $sql )
  23. . '</font></pre>' );
  24. }
  25.  
  26. return $query
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.