【问题标题】:PDO database connection failingPDO 数据库连接失败
【发布时间】: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


    【解决方案1】:

    变化:

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

    收件人:

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

    你得到什么消息?

    更新 1:

    您需要从 php.ini 中取消注释:extension=php_pdo_mysql.dll,然后重新启动 Apache。

    【讨论】:

    • 这个:Connection failed: could not find driver.
    • 从您的 php.ini 中取消注释 extension=php_pdo_mysql.dll,然后重新启动 Apache。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2023-03-02
    • 2020-05-05
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多