php - 致命错误: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);
}
帮我解决问题
解决方案
推荐阅读
- r - 如何将第一个变量的当前值与新创建的变量的先前值相加
- reactjs - React Redux 如何在平移时加载地图标记而不重新渲染所有内容?
- google-cloud-pubsub - Google PubSub 中的多个主题与单个主题
- angular - 对本地主机的 GET 请求在 Postman 上产生错误 404
- python - 将接缝从一个网格重新投影到另一个网格
- javascript - 如何向对象添加新参数
- javascript - 有没有一种方法可以在 javascript 中过滤 dict
- java - 无需用户操作的 JMeter 测试
- python - 在 Tk tkinter 中设置 root 的大小
- dataframe - 如何在 Julia 的专题地图中添加颜色条?