简体   繁体   中英

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. 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.

Change:

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

To:

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

What message do you get?

Update 1:

You need to uncomment: extension=php_pdo_mysql.dll from php.ini and then restart Apache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM