Codeigniter错误:调用未定义的函数mysql_pconnect()

I have updated my codeigniter version from 2.2.4 step by step to 3.0.6 and I get an error:

An uncaught Exception was encountered

Type: Error

Message: Call to undefined function mysql_pconnect()

Filename: path-to-project\system\database\drivers\mysql\mysql_driver.php

Line Number: 135

Backtrace:

File: path-to-project\application\controllers\Main.php
Line: 10
Function: __construct

File: path-to-project\index.php
Line: 315
Function: require_once

I have just replaced my index.php file and system directory with the new one and made some changes in my application according to tutorial.

and this is the Main controller:

class Main extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('main_model');
    }
}

What causes the problem?!

And this is the link of the tutorial.

doubinchou4219
doubinchou4219 在config/database.php中使用它:'dbdriver'=>'mysqli',(将mysql更改为mysqli)。
大约 4 年之前 回复
ds465456465
ds465456465 现在,问题来自codeigniter或我在我的代码中使用已弃用的mysql?
4 年多之前 回复
duanmu0834
duanmu0834 另外,请提交该教程的链接。
4 年多之前 回复
dsa89029
dsa89029 mysql_*从php5弃用并从php7中删除。切换到mysqli_*或PDO
4 年多之前 回复

3个回答

Thanks to Anant

I come to a conclusion:

I completely changed my old database.php file in config folder with the new one:

From:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = '';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

To:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '',
    'username' => '',
    'password' => '',
    'database' => '',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

And the error is gone!

donglongqiao9595
donglongqiao9595 谢谢,你救了我的一天。
2 年多之前 回复
dongtun1872
dongtun1872 嗨,我已经应用了您的解决方案,但错误仍然出现。 还有其他方法吗?
接近 3 年之前 回复
dsaob80228
dsaob80228 你的dbdriver配置值为空,你应该使用$ db ['default'] ['dbdriver'] ='mysqli';
接近 3 年之前 回复



PHP 5.5.x中不推荐使用的功能:</ p>


现在不推荐使用原始的MySQL扩展,并且在连接到数据库时会生成E_DEPRECATED错误 。 相反,使用MySQLi或PDO_MySQL扩展。</ p>
</ blockquote>

您正在使用已弃用的'mysql'</ code> dbdriver </ code> 。 找到 config / database.php </ code>文件并更改 dbdriver </ code>以使用'mysqli'</ code>:</ p>

 <  code> $ db ['default'] ['dbdriver'] ='mysqli';

</ code> </ pre>
</ div>

展开原文

原文

Deprecated features in PHP 5.5.x:

The original MySQL extension is now deprecated, and will generate E_DEPRECATED errors when connecting to a database. Instead, use the MySQLi or PDO_MySQL extensions.

You're using the deprecated 'mysql' dbdriver. Locate the config/database.php file and change dbdriver to use 'mysqli' :

$db['default']['dbdriver'] = 'mysqli'; 

duanlie3187
duanlie3187 是的,谢谢它的工作,但有一些问题,我说ci的旧项目版本是2.4.0但是在创建db并导入备份之后,还在config-> database.php'mysql'中更改为'mysqli'。 最后致命的错误消失但是heder的数据正在完善但是在xammp页面的身体内容的地方。 不知道为什么。 如果你有任何建议。
一年多之前 回复
drhzc64482
drhzc64482 这应该是公认的答案!
接近 2 年之前 回复



如果您在托管网站时发生此错误,请确保设置正确的PHP版本(CI使用的版本)。 </ p>
</ div>

展开原文

原文

If this error happened when you're hosting the website, make sure to set the correct PHP Version (the one your CI use).

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐