Daniel
Daniel

Reputation: 1

What is PDO database configuration in CodeIgniter?

In application/config/database.phpfor setting up a optimal database configuration should set the $db['default']['hostname'] = ''; to 'localhost' by use of mysql driver.

But when we use PDO driver for this configuration and localhost for the host name we see ERROR. What is PDO database hostname configuration in CodeIgniter with PDO driver shown below and what should place instead of question mark?

$db['default']['hostname'] = '?????';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'XXX';
$db['default']['dbdriver'] = 'PDO';

Upvotes: 0

Views: 7953

Answers (2)

Bora
Bora

Reputation: 10717

For the PDO driver, you should use the $config['dsn'] setting instead of hostname and database:

// PDO
$db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';

Documentations:

http://www.codeigniter.com/user_guide/database/connecting.html?highlight=pdo

http://www.codeigniter.com/user_guide/database/configuration.html

Upvotes: 2

user4419336
user4419336

Reputation:

If your trying to connect pdo try in codeigniter 3

$db['default'] = array(
'dsn'  => 'mysql:host=localhost; dbname=myproject; charset=utf8;',
'hostname' => 'localhost',
'username' => 'root',
'password' => '*********',
'database' => '',
'dbdriver' => 'pdo',

Upvotes: 3

Related Questions