实时托管站点上的PHP数据库连接错误-主机名相关

时间:2019-06-28 11:55:02

标签: php pdo

我在GoDaddy上托管了一个网站,该网站在尝试注册用户时出现以下错误(错误日志中)。 (某种数据库连接错误)。注册并单击“输入”后,所有用户详细信息都将显示在页面上。

  

堆栈跟踪:       #0 /home/ttio/public_html/tc.ttio.io/includes/dbconn.php(21):PDO-> __ construct('mysql:host =; dbn ...','ttio_tc','Teachingcomputi ... ')       #1 /home/ttio/public_html/tc.ttio.io/createuser.php(60):DbConn-> __ construct()       #2 {main}         在第21行的/home/ttio/public_html/tc.ttio.io/includes/dbconn.php中抛出

最初,我认为这与PHP版本有关,但是已经升级,但是仍然无法正常工作。

在注册用户时,用户的注册详细信息仅显示在屏幕上,而不是转到createuser.php页面。在Bluehost上,当客户服务升级PHP版本时,一切正常。

我更改了**includes/dbconn.php**代码,现在如下所示:

<?php
// Extend this class to re-use db connection
class DbConn
{
    public $conn;
    public function __construct()
    {
        require 'dbconf.php';
        $this->host = $host; // Host name
        $this->username = $username; // Mysql username
        $this->password = $password; // Mysql password
        $this->db_name = $db_name; // Database name
        $this->tbl_prefix = $tbl_prefix; // Prefix for all database tables
        $this->tbl_members = $tbl_members;
        $this->tbl_quiz = $tbl_quiz;
        $this->tbl_attempts = $tbl_attempts;
        $this->tbl_payments = $tbl_payments;


        // Connect to server and select database.
        $this->conn = new PDO('mysql:host=;dbname=uuio_tc;', $username, $password);
        $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
}

我怀疑问题出在这行>> $this->conn = new PDO('mysql:host=;dbname=uuio_tc;', $username, $password);和主机上,但是我不确定要更改什么来解决该错误。

据我所知,dbconf文件也已正确设置,如下(某些个人信息已更改)

   <?php
    //DATABASE CONNECTION VARIABLES
    $host = ""; // Host name
    $username = "uuio_tc"; // Mysql username
    $password = "abcabcabc123123123#"; // Mysql password
    $db_name = "uuio_tc"; // Database name

    //DO NOT CHANGE BELOW THIS LINE UNLESS YOU CHANGE THE NAMES OF THE MEMBERS AND LOGINATTEMPTS TABLES

    $tbl_prefix = ""; //***PLANNED FEATURE, LEAVE VALUE BLANK FOR NOW*** Prefix for all database tables
    $tbl_members = $tbl_prefix."members";
    $tbl_quiz = $tbl_prefix."quizResults";
    $tbl_attempts = $tbl_prefix."loginAttempts";
    $tbl_payments = $tbl_prefix."payments";

在使用开发人员检查工具时,控制台错误列出:

  

无法加载资源:服务器的状态为500(内部服务器错误)

有什么建议吗?

0 个答案:

没有答案