Created
March 8, 2018 07:01
-
-
Save anonymous/06e2c1fe2d3ab6ece4c453539f8c77fb to your computer and use it in GitHub Desktop.
Mysql to Mysqli minimilistic adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('mysql_connect')) { | |
global $__link; | |
function _link( $link = null ) { | |
global $__link; | |
if ( $link == null ) { | |
$link = $__link; | |
} | |
return $link; | |
} | |
function mysql_connect( $host, $username, $password ) { | |
global $__link; | |
$__link = mysqli_connect( $host, $username, $password ); | |
return $__link; | |
} | |
function mysql_select_db( $database, $link = null ) { | |
return mysqli_select_db( _link( $link ), $database ); | |
} | |
function mysql_query( $sql, $link = null ) { | |
return mysqli_query( _link( $link ), $sql ); | |
} | |
function mysql_error( $link = null ) { | |
return mysqli_error( _link( $link ) ); | |
} | |
function mysql_free_result( $res ) { | |
mysqli_free_Result( $res ); | |
} | |
function mysql_get_server_info( $link = null ) { | |
return mysqli_get_server_info( _link( $link ) ); | |
} | |
function mysql_fetch_assoc( $res ) { | |
return mysqli_fetch_assoc( $res ); | |
} | |
function mysql_num_fields( $res ) { | |
return mysqli_num_fields( $res ); | |
} | |
function mysql_fetch_field( $res, $offset = 0 ) { | |
$offset ++; // at least one iteration | |
for ( $i = 0, $datum = null; $i < $offset; $i ++ ) { | |
$datum = mysqli_fetch_field( $res ); | |
} | |
return $datum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment