I'm tryng to connect a different database from a php function (assuming there's a current connection to another database). I'm using mysql_connect()
with new_link
parameter set to TRUE as you can see below. How is it possible the following code returns global_thread_id=16357138 local_thread_id=16357139 current_global=16357139
(meaning local connection overriden previous connection) despite the TRUE in mysql_connect()
Also in php settings, sql.safe_mode = OFF
// Class static method
static function Query($sql) {
$global_thread_id = mysql_thread_id();
if ($link = mysql_connect(FB_DB_HOST, FB_DB_USER, FB_DB_PASS, true))
{
$local_thread_id = mysql_thread_id($link);
echo 'global_thread_id='.$global_thread_id.' local_thread_id='.$local_thread_id.' current_global='.mysql_thread_id();
}
}
mysql_thread_id() fetch the latest thread id, not a "global"
php manual for mysql_thread_id says:
Retrieves the current thread ID
// Class static method
static function Query($sql) {
/* fetch latest thread id = global */
$global_thread_id = mysql_thread_id();
if ($link = mysql_connect(FB_DB_HOST, FB_DB_USER, FB_DB_PASS, true))
{
/* fetch thread id from $link */
$local_thread_id = mysql_thread_id($link);
/* echo 2 vars and the latest thread id = same as link */
echo 'global_thread_id='.$global_thread_id.' local_thread_id='.$local_thread_id.' current_global='.mysql_thread_id();
}
}