php Codeigniter 错误:调用未定义的函数 mysql_pconnect()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36822462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter error: Call to undefined function mysql_pconnect()
提问by Afshin
I have updated my codeigniter version from 2.2.4 step by step to 3.0.6 and I get an error:
我已将我的 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
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.
我刚刚用新的替换了我的 index.php 文件和系统目录,并根据教程对我的应用程序进行了一些更改。
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 linkof the tutorial.
而这是链接的教程。
采纳答案by Afshin
Thanks to Anant
感谢Anant
I come to a conclusion:
我得出一个结论:
I completely changed my old database.php file in config folder with the new one:
我用新的完全改变了我在 config 文件夹中的旧 database.php 文件:
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!
错误消失了!
回答by DotBot
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.
原始 MySQL 扩展现已弃用,并且在连接到数据库时会生成 E_DEPRECATED 错误。相反,使用 MySQLi 或 PDO_MySQL 扩展。
You're using the deprecated 'mysql'
dbdriver. Locate the config/database.php
file and change dbdriver
to use 'mysqli'
:
您正在使用已弃用的'mysql'
dbdriver。找到config/database.php
文件并更改dbdriver
为使用'mysqli'
:
$db['default']['dbdriver'] = 'mysqli';
回答by maneesh kumar gautam
go to application/config/database.php
and just change mysql
to mysqli
转到 application/config/database.php
并更改mysql
为mysqli
like this was before:
以前是这样的:
$db['default']['dbdriver'] = 'mysql';
this was after solution:
这是在解决方案之后:
$db['default']['dbdriver'] = 'mysqli';
i just change mysql to mysqli. that's it
我只是将 mysql 更改为 mysqli。就是这样
my error was
我的错误是
Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() in E:\manish_data\software\xampp\htdocs\ci2\system\database\drivers\mysql\mysql_driver.php:92 Stack trace: #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(Array, 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): Users->index() #6 E:\manish_data\software\xampp\htdocs\ci2\index.php(202): require_once('E:\manish_data\...') #7 {main} thrown in E:\manish_data\software\xampp\htdocs\ci2\system\database\drivers\mysql\mysql_driver.php on line 92
致命错误:未捕获的错误:调用 E:\manish_data\software\xampp\htdocs\ci2\system\database\drivers\mysql\mysql_driver.php:92 中的未定义函数 mysql_pconnect() 堆栈跟踪:#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(Array, 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): Users->index() #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 行
回答by Blaze Tama
If this error happened when you're hosting the website, make sure to set the correct PHP Version (the one your CI use).
如果在您托管网站时发生此错误,请确保设置正确的 PHP 版本(您的 CI 使用的版本)。