首页 > 解决方案 > 致命错误:cpanel 中的数据库错误

问题描述

我已将网站上传到 c 面板。当我尝试从浏览器访问它时,出现以下错误:

致命错误:数据库错误 0:linkID == False。连接失败。警告:mysql_connect():第 128 行 /home/anyonstr/school.anyonstrendtakesolution.co.ke/classes/Database.class.php 中的用户 'root'@'localhost' 的访问被拒绝(使用密码:否)

致命错误:数据库错误 0:linkID == False。连接失败。在第 173 行的 /home/anyonstr/school.anyonstrendtakesolution.co.ke/classes/Database.class.php

但它在 xampp 中工作正常。这是我的代码,

class Database
{
# Constructor. Create an instance of this class with this.
# You would generally need just one.


private static $_singleton;
private $linkID;
private function __construct($hostname, $username, $password,            
$database, 
$debug=False){
    $this->debug = $debug;
    $this->linkID = 0;
    $this->queryID = 0;
    $this->queryCount = 0;
    $this->errNo = 0;
    $this->errStr = '';

    //$this->_connection = mysql_connect();
     if (! ($hostname and $username and $database))
        $this->halt('Missing parameters.');

    $this->linkID = mysql_connect($hostname, $username, $password);

    if (! $this->linkID)
        $this->halt('linkID == False. Connect failed.');

    if (! mysql_select_db($database, $this->linkID))
        $this->halt("Cannot use database '$database'.");

   }
   public static function getInstance($hostname, $username, $password, 
  $database, $debug=False){
    if (is_null (self::$_singleton)) {
        self::$_singleton = new Database($hostname, $username, $password, 
  $database, $debug=False);
    }
    return self::$_singleton;
    }


   /*  function Database($hostname, $username, $password, $database, 
   $debug=False)
   {
    $this->debug = $debug;
    $this->linkID = 0;
    $this->queryID = 0;
    $this->queryCount = 0;
    $this->errNo = 0;
    $this->errStr = '';

    if (! ($hostname and $username and $database))
        $this->halt('Missing parameters.');


    $this->linkID = mysql_connect($hostname, $username, $password);


    if (! $this->linkID)
        $this->halt('linkID == False. Connect failed.');

    if (! mysql_select_db($database, $this->linkID))
        $this->halt("Cannot use database '$database'.");
    }*/

    # Halt because an error occured.
    function halt($msg)
   {
    trigger_error(
        sprintf("Database error %d: %s<br />%s\n",
                $this->errNo, $this->errStr, $msg),
        E_USER_ERROR);
    }

帮我解决问题

标签: php

解决方案


推荐阅读