codeigniter 3.1 PDO mysql Error Number: 3D000/1046 No database selected

ぃ、小莉子 提交于 2019-12-10 18:47:34

问题


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


回答1:


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.




回答2:


My config:

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

You can see here: CodeIgniter PDO database driver not working



来源:https://stackoverflow.com/questions/32836797/codeigniter-3-1-pdo-mysql-error-number-3d000-1046-no-database-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!