Advertisement
eyuprog

PHP Mysql_Connect PHP 5.6++

Sep 3rd, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.03 KB | None | 0 0
  1. <?php
  2. if (!function_exists("mysql_connect")){
  3.   define("MYSQL_ASSOC", MYSQLI_ASSOC);
  4.   define("MYSQL_NUM", MYSQLI_NUM);
  5.   define("MYSQL_BOTH", MYSQLI_BOTH);
  6.  
  7.   function mysql_fetch_array($result, $result_type = MYSQL_BOTH){
  8.     $row = mysqli_fetch_array($result, $result_type);
  9.     return is_null($row) ? false : $row;
  10.   }
  11.  
  12.   function mysql_fetch_assoc($result){
  13.     $row = mysqli_fetch_assoc($result);
  14.     return is_null($row) ? false : $row;
  15.   }
  16.  
  17.   function mysql_fetch_row($result) {
  18.     $row = mysqli_fetch_row($result);
  19.     return is_null($row) ? false : $row;
  20.   }
  21.  
  22.   function mysql_fetch_object($result) {
  23.     $row = mysqli_fetch_object($result);
  24.     return is_null($row) ? false : $row;
  25.   }
  26.  
  27.   function mysql_connect($host, $username, $password, $new_link = FALSE, $client_flags = 0){
  28.     global $global_link_identifier;
  29.     $global_link_identifier = mysqli_connect($host, $username, $password);
  30.     return $global_link_identifier;
  31.   }
  32.  
  33.   function mysql_pconnect($host, $username, $password, $client_flags = 0){
  34.     global $global_link_identifier;
  35.     $global_link_identifier = mysqli_connect("p:".$host, $username, $password);
  36.     return $global_link_identifier;
  37.   }
  38.  
  39.   function mysql_select_db($dbname, $link_identifier = null){
  40.     global $global_link_identifier;
  41.     if($link_identifier == null) {
  42.       $link_identifier = $global_link_identifier;
  43.     }
  44.     return mysqli_select_db($link_identifier, $dbname);
  45.   }
  46.  
  47.   function mysql_ping($link_identifier = null){
  48.     global $global_link_identifier;
  49.     if($link_identifier == null) {
  50.       $link_identifier = $global_link_identifier;
  51.     }
  52.     return mysqli_ping($link_identifier);
  53.   }
  54.  
  55.   function mysql_query($stmt, $link_identifier = null){
  56.     global $global_link_identifier;
  57.     if($link_identifier == null) {
  58.       $link_identifier = $global_link_identifier;
  59.     }
  60.     return mysqli_query($link_identifier, $stmt);
  61.   }
  62.  
  63.   function mysql_num_rows($result){
  64.     return mysqli_num_rows($result);
  65.   }
  66.  
  67.   function mysql_affected_rows($link_identifier = NULL){  
  68.     global $global_link_identifier;
  69.     if($link_identifier == null) {
  70.       $link_identifier = $global_link_identifier;
  71.     }
  72.     return mysqli_affected_rows($link_identifier);
  73.   }
  74.  
  75.   function mysql_list_tables($dbname, $link_identifier = null){
  76.     global $global_link_identifier;
  77.     if($link_identifier == null) {
  78.       $link_identifier = $global_link_identifier;
  79.     }
  80.     $sql = "SHOW TABLES FROM $dbname";
  81.     $result = mysql_query($sql, $link_identifier);
  82.     return $result;
  83.   }
  84.  
  85.   function mysql_error($link_identifier = null){
  86.     global $global_link_identifier;
  87.     if($link_identifier == null) {
  88.       $link_identifier = $global_link_identifier;
  89.     }
  90.     return mysqli_error($link_identifier);
  91.   }
  92.  
  93.   function mysql_errno($link_identifier = null){
  94.     global $global_link_identifier;
  95.     if($link_identifier == null) {
  96.       $link_identifier = $global_link_identifier;
  97.     }
  98.     return mysqli_errno($link_identifier);
  99.   }
  100.  
  101.   function mysql_insert_id($link_identifier = NULL){
  102.     global $global_link_identifier;
  103.     if($link_identifier == null) {
  104.       $link_identifier = $global_link_identifier;
  105.     }
  106.     return mysqli_insert_id($link_identifier);
  107.   }
  108.  
  109.   function mysql_close($link_identifier = NULL){
  110.     return true;
  111.   }
  112.  
  113.   function mysql_real_escape_string($unescaped_string, $link_identifier = null){
  114.     global $global_link_identifier;
  115.     if($link_identifier == null) {
  116.       $link_identifier = $global_link_identifier;
  117.     }
  118.     return mysqli_real_escape_string($link_identifier, $unescaped_string);
  119.   }
  120.  
  121.   function mysql_data_seek($result, $row_number){
  122.     return mysqli_data_seek($result, $row_number);
  123.   }
  124.  
  125.   function mysql_result($result, $row=0, $col=0){
  126.     $numrows = mysqli_num_rows($result);
  127.     if($numrows && $row <= ($numrows-1) && $row >= 0){
  128.       mysqli_data_seek($result, $row);
  129.       $resultrow = (is_numeric($col)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result);
  130.       if (isset($resultrow[$col])){
  131.         return $resultrow[$col];
  132.       }
  133.     }
  134.     return false;
  135.   }
  136.  
  137.   function mysql_escape_string($s, $link_identifier = null){
  138.     global $global_link_identifier;
  139.     if($link_identifier == null) {
  140.       $link_identifier = $global_link_identifier;
  141.     }
  142.     return mysqli_real_escape_string($link_identifier, $s);
  143.   }
  144.  
  145.   function mysql_field_name($result, $i) {
  146.     return mysqli_fetch_field_direct($result, $i);
  147.   }
  148.  
  149.   function mysql_free_result($result) {
  150.     return mysqli_free_result($result);
  151.   }
  152.  
  153.   function mysql_get_server_info($link_identifier = null){
  154.     global $global_link_identifier;
  155.     if($link_identifier == null) {
  156.       $link_identifier = $global_link_identifier;
  157.     }
  158.     return mysqli_get_server_info($link_identifier);
  159.   }
  160.  
  161.   function mysql_set_charset($csname, $link_identifier = null){
  162.     global $global_link_identifier;
  163.     if($link_identifier == null) {
  164.       $link_identifier = $global_link_identifier;
  165.     }
  166.     return mysqli_set_charset($link_identifier, $csname);
  167.   }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement