3

I had issue with upgrading codeignier 2.xx to 3.xx before and I can not found any completed answer for me. So I'd like to share how I solved it.

In Codeignier official web site show how to connect PDO with Mysql as below

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

$config[‘dsn’] = ‘mysql:host=localhost;dbname=mydatabase’

https://www.codeigniter.com/user_guide/database/connecting.html

But I still could not make it work as it was showing error

Invalid or non-existent PDO subdriver

Some site shown how to fixe this by add this to hostname

$db ['default'] ['hostname'] = 'mysql:host=localhost';

But I still got error

Error Number: 3D000/1046

No database selected

thep
  • 176
  • 1
  • 1
  • 8

2 Answers2

6

I spend time to debug a while I found that once dbdriver is selected to 'pdo' Codeigniter check dsn detail from $db ['default'] ['hostname'] not in $db ['default'] ['dns'] including database name like below.

$db ['default'] ['hostname'] = 'mysql:host=localhost;dbname=my_database';

I hope this will help for anyone may got error like mine.

thep
  • 176
  • 1
  • 1
  • 8
6

My config:

    'dsn'   => 'mysql:host=localhost;dbname=codeigniter3',
    'dbdriver' => 'pdo'

You can see here: CodeIgniter PDO database driver not working

Community
  • 1
  • 1
Kevin
  • 61
  • 1
  • 3