php - Detect if mysql or mysqli is being called for connection -
is there way check type of mysql connection being called mysql or mysqli. want have if statement call mysql or mysqli connection until can change out coding.
this current connection file. duplicating what's below mysqli accomplish i'm trying do?
$dbc = mysql_connect ($db_server, $db_user, $db_pass); mysql_select_db ($db_name) or die(mysql_error()); $g_link = false; function getdbconn() { global $g_link; if( $g_link ) return $g_link; $g_link = mysql_connect( 'localhost', 'username', 'password') or die('could not connect server.' ); mysql_select_db('social_db', $g_link) or die('could not select database.'); return $g_link; } function cleanupdb() { global $g_link; if( $g_link != false ) mysql_close($g_link); $g_link = false; }
you can use get_resource_type function:
if(is_resource($g_link) && get_resource_type($g_link)=='mysql link'){ echo 'mysql'; }else{ if(is_object($g_link) && get_class($g_link)=='mysqli'){ echo 'mysqli'; } } also, it's better save connection type when want create connection , use it.
Comments
Post a Comment