我已将我的codeigniter版本从2.2.4一步一步更新到3.0.6,我收到错误:
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
我刚刚将index.php文件和系统目录替换为新目录,并根据教程对我的应用程序进行了一些更改。
这是主控制器:
class Main extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('main_model');
}
}
导致问题的原因是什么?!
本教程的this is the link。
答案 0 :(得分:66)
Deprecated features in PHP 5.5.x:
现在不推荐使用原始MySQL扩展,并且在连接到数据库时会生成E_DEPRECATED错误。相反,请使用MySQLi或PDO_MySQL扩展。
您正在使用已弃用的'mysql'
dbdriver
。找到config/database.php
文件并将dbdriver
更改为使用'mysqli'
:
$db['default']['dbdriver'] = 'mysqli';
答案 1 :(得分:11)
感谢 Anant
我得出结论:
我在配置文件夹中使用新文件完全更改了旧的database.php文件:
自:
$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;
要:
$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
);
错误消失了!
答案 2 :(得分:4)
转到application / config / database.php
只需将mysql
更改为mysqli
喜欢 这是以前的
$db['default']['dbdriver'] = 'mysql';
这是在解决之后:
$db['default']['dbdriver'] = 'mysqli';
我只是将mysql更改为mysqli。就是这样
我的错误是
致命错误:未捕获错误:调用未定义函数 mysql_pconnect()在 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ database \ drivers \ mysql \ mysql_driver.php:92 堆栈跟踪:#0 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ database \ DB_driver.php(116): CI_DB_mysql_driver-> db_pconnect()#1 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ database \ DB.php(149): CI_DB_driver-> initialize()#2 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ core \ Loader.php(347): DB(数组,NULL)#3 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ application \ models \ usermodel.php(20): CI_Loader-> database()#4 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ application \ controllers \ users.php(15):UserModel-> getUsers()#5 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ core \ CodeIgniter.php(360): 用户->索引()#6 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ index.php(202): require_once('E:\ manish_data \ ...')#7 {main}被抛出 E:\ manish_data \ software \ xampp \ htdocs \ ci2 \ system \ database \ drivers \ mysql \ mysql_driver.php 在第92行
答案 3 :(得分:0)
如果您在托管网站时发生此错误,请务必设置正确的PHP版本(CI使用的版本)。