[英]PDO database connection failing
我有一個連接到數據庫的文件。 當我在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
任何其他名稱。
更改:
exit('Unable to connect to database.');
至:
echo 'Connection failed: ' . $e->getMessage();
exit();
你收到什么消息?
更新1:
您需要取消注釋:php.ini中的extension=php_pdo_mysql.dll
,然后重新啟動Apache。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.