首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用new_link=TRUE和sql.safe_mode = OFF的多个数据库连接

问不使用new_link=TRUE和sql.safe_mode = OFF的多个数据库连接
EN

Stack Overflow用户
提问于 2012-08-24 04:28:45
回答 1查看 421关注 0票数 0

我是tryng来连接与php函数不同的数据库(假设存在到另一个数据库的当前连接)。我使用的是mysql_connect(),new_link参数设置为TRUE,如下所示。下面的代码如何可能返回global_thread_id=16357138 local_thread_id=16357139 current_global=16357139 (意思是本地连接覆盖了以前的连接),尽管mysql_connect()中的值为真

同样在php设置中,sql.safe_mode = OFF

代码语言:javascript
复制
// 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();   
       }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-24 05:26:36

mysql_thread_id()获取最新的线程id,而不是“全局”

id手册上写着:

检索当前线程ID。

代码语言:javascript
复制
// 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();   
       }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12103156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档