ci mysql pdo,codeigniter 3.1 PDO mysql错误号:3D000 / 1046未选择数据库

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’

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

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值