[英]PDO database connection failing
I have a file that connects to a database. 我有一个连接到数据库的文件。 When i ran it on localhost it worked great, but since placing it online the connection fails.
当我在localhost上运行时,它运行良好,但是由于将其置于联机状态,因此连接失败。 My code is;
我的代码是;
<?php
// List of events
$json = array();
// Query that retrieves events
$requete = "SELECT * FROM rota ORDER BY id";
// connection to the database
try {
$bdd = new PDO('mysql:host=IllusionsMembers.db.12196899.hostedresource.com;dbname=IllusionsMembers', 'IllusionsMembers', 'password');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
// Execute the query
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
// sending the encoded result to success page
echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
?>
i have a feeling it may be the host name causing errors as i have never used any other name aprt from localhost
in any other project. 我觉得这可能是导致错误的主机名,因为我从未在任何其他项目中使用过来自
localhost
任何其他名称。
Change: 更改:
exit('Unable to connect to database.');
To: 至:
echo 'Connection failed: ' . $e->getMessage();
exit();
What message do you get? 你收到什么消息?
Update 1: 更新1:
You need to uncomment: extension=php_pdo_mysql.dll
from php.ini and then restart Apache. 您需要取消注释:php.ini中的
extension=php_pdo_mysql.dll
,然后重新启动Apache。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.