CodeIgniter PDO数据库驱动程序不工作 [英] CodeIgniter PDO database driver not working
问题描述
我想在我的CodeIgniter应用程序中使用PDO MySQL驱动程序。这是我的数据库配置:
I'm trying to use the PDO MySQL driver in my CodeIgniter application. This is my database config:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'testdatabase';
$db['default']['dbdriver'] = 'pdo';
$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;
但是,当我加载控制器时收到此错误:
However, I'm getting this error when I load a controller:
致命错误:
中出现消息invalid
数据源名称的未捕获异常PDOExceptionC:\ xampp\htdocs \ testsite\system\database\drivers\pdo\pdo_driver.php:114
Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in C:\xampp\htdocs\testsite\system\database\drivers\pdo\pdo_driver.php:114
我已检查数据源在 pdo_driver.php
中使用 die($ this-> hostname);
>
I've checked the data source using die($this->hostname);
in pdo_driver.php
and it's coming out as:
localhost;dbname=testdatabase
,所以它获得正确的数据库名称。数据库存在,我确实有MySQL运行。
so it is getting the correct database name. The database exists and I do have MySQL running.
这里可能出现什么问题?谢谢。
What could be going wrong here? Thank you.
推荐答案
不应该是这样。
localhost;dbname=testdatabase
应为
mysql:dbname=testdatabase;host=localhost;
这篇关于CodeIgniter PDO数据库驱动程序不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!