rAthus

MySQL to MySQLi migration: easy backward compatibility

Nov 21st, 2018 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MySQLi connection
  2. $mysqli_link = mysqli_connect('HOST','USER','PASSWORD','DATABASE');
  3. $mysqli_link->set_charset('utf8'); // if needed, depending on your configuration
  4.  
  5. // backward compatibility of old MySQL functions by rAthus
  6. function mysql_connect() {
  7.     return true;
  8. }
  9. function mysql_select_db() {
  10.     return true;
  11. }
  12. function mysql_query($q) {
  13.     global $mysqli_link;
  14.     return mysqli_query($mysqli_link,$q);
  15. }
  16. function mysql_fetch_array($r) {
  17.     return mysqli_fetch_array($r,MYSQLI_ASSOC);
  18. }
  19. function mysql_num_rows($r) {
  20.     return mysqli_num_rows($r);
  21. }
  22. function mysql_error() {
  23.     global $mysqli_link;
  24.     return mysqli_error($mysqli_link);
  25. }
  26. function mysql_insert_id() {
  27.     global $mysqli_link;
  28.     return mysqli_insert_id($mysqli_link);
  29. }
  30. function mysql_close($mysqli_link) {
  31.     global $mysqli_link;
  32.     return mysqli_close($mysqli_link);
  33. }
  34.  
  35. // if you have errors like "this is incompatible with sql_mode=only_full_group_by", try enabling this:
  36. //mysqli_query($mysqli_link,'SET sql_mode=""');
Add Comment
Please, Sign In to add comment