douyue6520 2014-03-27 00:56
浏览 138

PDO数据库连接失败

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.

  • 写回答

1条回答 默认 最新

  • dongtanhe4607 2014-03-27 01:00
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题