加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在codeIgniter中不能与mysqli驱动程序一起使用的持久连接

发布时间:2020-12-13 16:53:22 所属栏目:PHP教程 来源:网络整理
导读:我在本地开发环境中有这个db-configuration $db['default']['hostname'] = 'localhost';$db['default']['username'] = ''; //Actual username is put inside these quotes$db['default']['password'] = '';$db['default']['database'] = ''; //Actual name o
我在本地开发环境中有这个db-configuration

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = ''; //Actual username is put inside these quotes
$db['default']['password'] = '';
$db['default']['database'] = ''; //Actual name of database is put inside quotes
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = APPPATH .'cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

当我转移到生产服务器它不起作用所以我尝试了很多东西,但似乎有一件事似乎是将dbdriver更改为mysqli而不是mysql.但我也很想把db_debug放到FALSE(所以它“工作”不是正确的陈述)

我已经阅读了很多这方面的内容,但我在任何地方都找不到答案. (我不满意:“改为debug = false,它会起作用”)

我想看看实际问题是什么,所以我将本地服务器更改为mysqli驱动程序,然后我收到错误:

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: C:Program Fileswampwwwmellomgarden2systemdatabaseDB_driver.php

Line Number: 124

经过一番挖掘后,我发现db_connect()和db_pconnect()的工作方式完全相同:

>如果查看system / database / drivers / mysqli / mysqli_driver.php – 似乎connect()和pconnect()的工作方式完全相同,因为pconnect()只是调用connect()函数.

所以$db [‘default’] [‘pconnect’] = TRUE;使用mysqli驱动程序时完全没用.

function db_connect()
{
    if ($this->port != '')
    {
        return @mysqli_connect($this->hostname,$this->username,$this->password,$this->database,$this->port);
    }
    else
    {
        return @mysqli_connect($this->hostname,$this->database);
    }

}
// --------------------------------------------------------------------

/**
 * Persistent database connection
 *
 * @access  private called by the base class
 * @return  resource
 */
function db_pconnect()
{
    return $this->db_connect();
}

仔细看看上面的db_connect()和db_pconnect() – 这些都是有争议的.我删除了@的返回值然后得到了这个:

严重性:警告

消息:mysqli_connect():( 08004/1040):连接太多

文件名:mysqli / mysqli_driver.php

行号:76

这是FAR更多的解释性错误

所以我的想法是mysqli驱动程序的db_pconnect应该是这样的:

function db_pconnect()
    {       
                 $this->hostname = 'p:' . ltrim($this->hostname,'p:');                                  
                 return $this->db_connect();
    }

这是CodeIgniter开发团队的完全错过,还是我错过了什么?

解决方法

参考 your other thread我假设你指定使用持久连接似乎是真的,但是看看CodeIgniter的源代码我们可以得出一个不同的结论: The MySQL driver实际上注意到这个选项开始设置. Whereas the MySQLi driver,正如您正确分析的那样,没有.这也在 bug report中被注意到并且已经修复.

如你所见,the whole MySQLi driver class was rewritten in the development branch.

因此,到目前为止,您已经使用了持久连接,但是(不情愿地)在切换到MySQLi时停止使用它们,因为此修复程序尚未发布…如果这是一个选项,您可以尝试使用开发分支. (或者只替换这个单个文件……也应该工作.)

您的另一个选择是,就像我在其他答案中所述,您可以简要估计应用程序使用的连接,并根据您的实际需要调整max_connections限制.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读