【发布时间】:2014-03-27 00:56:40
【问题描述】:
我有一个连接到数据库的文件。当我在 localhost 上运行它时效果很好,但是由于将其置于联机状态,因此连接失败。我的代码是;
<?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));
?>
我感觉这可能是导致错误的主机名,因为我从未在任何其他项目中使用过来自 localhost 的任何其他名称。
【问题讨论】:
标签: php mysql pdo connection