codeigniter 3.1 PDO mysql错误号:3D000/1046未选择数据库 [英] codeigniter 3.1 PDO mysql Error Number: 3D000/1046 No database selected
问题描述
我之前将codeignier 2.xx升级到3.xx时遇到问题,但找不到完整的答案.所以我想分享我的解决方法.
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.
在Codeignier官方网站上,如下所示显示了如何将PDO与Mysql连接
In Codeignier official web site show how to connect PDO with Mysql as below
对于PDO驱动程序,您应该使用$ config [‘dsn’]设置 主机名"和数据库":
For the PDO driver, you should use the $config[‘dsn’] setting instead of ‘hostname’ and ‘database’:
$ config [‘dsn’] =‘mysql:host = localhost; dbname = mydatabase’
$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
无效或不存在的PDO子驱动程序
Invalid or non-existent PDO subdriver
一些网站显示了如何通过将其添加到主机名来解决此问题
Some site shown how to fixe this by add this to hostname
$ db ['default'] ['hostname'] ='mysql:host = localhost';
$db ['default'] ['hostname'] = 'mysql:host=localhost';
但是我仍然有错误
错误号:3D000/1046
Error Number: 3D000/1046
未选择数据库
推荐答案
我花时间调试了一段时间,我发现一旦将dbdriver选择为'pdo',Codeigniter就会从$ db中检查dsn详细信息['default'] ['hostname ']不在 $ db ['default'] ['dns']包括如下数据库名称.
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';
$db ['default'] ['hostname'] = 'mysql:host=localhost;dbname=my_database';
我希望这对任何可能遇到像我这样的错误的人都有帮助.
I hope this will help for anyone may got error like mine.
这篇关于codeigniter 3.1 PDO mysql错误号:3D000/1046未选择数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!