2014-03-27 139 views
0

我有一個連接到數據庫的文件。當我在localhost上運行它時效果很好,但是由於將它放置在線上,連接失敗。我的代碼是;PDO數據庫連接失敗

<?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)); 

?> 

我有可能是主機名導致錯誤,因爲我從來沒有在任何其他項目中使用的任何其他名稱APRT從localhost的感覺。

回答

0

變化:

exit('Unable to connect to database.'); 

要:

echo 'Connection failed: ' . $e->getMessage(); 
exit(); 

你會得到什麼樣的信息?

更新1:

您需要取消註釋:extension=php_pdo_mysql.dll從php.ini文件,然後重新啓動Apache。

+0

this:'連接失敗:找不到驅動程序'。 – Braydos1986

+0

從您的php.ini中取消註釋extension = php_pdo_mysql.dll,然後重新啓動Apache。 –