本文介绍了Mysql-PDO错误-无效的目录名称:1046未选择数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PDO有问题,而且我绝对看不到他的来历.我不能质疑我的MySQL数据库.为了进行测试,我使用了以下代码(之前为连接配置的参数非常糟糕:

I have a problem with PDO, and I see absolutely no where he come. I can not question my MySQL database. Just to test I used the following code (having quite sour previously configured the parameters for the connection:

try {
    $dbh= new PDO('mysql:host=serverName;dbname=Mydatabase','user','password');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e) {
    die('Erreur : ' . $e->getMessage());
}

var_dump($dbh);    // gives : object(PDO)#1 (0) { }

$res=$dbh->query('SELECT * FROM table');

使用MySQL正确建立连接,但查询后出现此错误:

The connection is made correctly with MySQL but after query I get this error:

该代码可在本地计算机上运行,​​但是一旦我将其联机(cPanel),它就会向我显示此错误.我必须在.htaccess中配置PDO吗?

The code works on a local machine, but as soon as I put it online (cPanel) it shows me this error. Do I have to configure PDO in .htaccess?

我绝对不明白问题出在哪里.有人有主意吗?

I absolutely do not understand where the problem come. Someone would have an idea?

推荐答案

帮助Mysql解析句柄.

Help Mysql resolve the handle by.

代替:

$res=$dbh->query('SELECT * FROM table');

尝试:

$res=$dbh->query('SELECT * FROM Mydatabase.table');

这篇关于Mysql-PDO错误-无效的目录名称:1046未选择数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:55