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[\
According to CodeIgniter's Database Configuration page,
For the PDO driver, you should change the 'hostname => 'localhost'
' to "'hostname' => mysql:host=localhost
" like below:
$db['default'] = array(
'dsn' => '',
'hostname' => 'mysql:host=localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
.....
.....
);
This should not be the case.
localhost;dbname=testdatabase
should be
mysql:dbname=testdatabase;host=localhost;
On file /application/config/database.php where is
$db['default']['hostname'] = 'localhost';
must be
$db['default']['hostname'] = 'mysql:host=localhost';
localhost or your database host.
PDO driver require a full DSN string to be provided. The string like this
'dsn' = ‘mysql:host=localhost;dbname=databasename’;
when you use this string you should remove host and databasename value from array. I think following example gives you an idea.
$db['default'] = array(
'dsn' => 'mysql:host=localhost;dbname=codeigniter3',
'hostname' => '',
'username' => 'root',
'password' => '',
'database' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Thanks