繁体   English   中英

错误1045:通过扩展类连接时,使用密码NO…拒绝用户'root'@'localhost'的访问

[英]error 1045: access denied for user 'root'@'localhost' using password NO… when connecting through extended classes,others

我有一个没有问题的连接数据库的类。 在扩展该类时,相同的连接将失败。 凭据可在phpMyAdmin和命令行中使用。

尝试连接到服务器时出现的错误:

1045: Access denied for user 'phpClasses'@'Jesse-Server' (using password: NO) 

我还尝试了具有相同结果的备用凭据。

以下是父类,子类,调用者模型的构造函数和属性定义:

//Database.php
private $dbhost;
private $dbname;
private $dbusername;
private $dbuserpassword;
private $dbtableprefix;
private $dbport;
protected $dbC;
public function __construct($ndbhost = "localhost", $ndbname = "", $ndbusername = "", $ndbuserpassword = "", $ndbtableprefix = " ", $ndbport = 3600)
{
$this->dbhost = $ndbhost; // Default = localhost
$this->dbname = $ndbname; // Default = None
$this->dbusername = $ndbusername; //Default = None
$this->dbuserpassword = $ndbuserpassword; // Default = None
$this->dbtableprefix = $ndbtableprefix; //Default = None sets the prefix before the table name so that it can be used with the same db with different tables.
$this->dbport = $ndbport; // Default  = 3600
// starting the connection
@ $this->dbC = new mysqli($this->dbhost, $this->dbusername, $this->dbuserpassword, $this->dbname);//, $this->dbport);
if ($this->dbC->connect_error) {
  //catch error connecting.
  die("There was a connection error while attempting to connect to the database " . $this->dbname . " on " . $this->dbhost . ":" . $this->dbport . ". The following is the error that we received back: <strong>" . $this->dbC->connect_errno . ": " . $this->dbC->connect_error . "</strong>\n Please correct this issue, if you need assistance see your database or IT administrator.");
}else{
  //echo "Connected to " . $this->dbname . " on " . $this->dbhost . ":" . $this->dbport;
}
}

现在孩子

//QueryBuilder.php
protected $dbC;
private $host;
private $dbName;
private $dbUser;
private $dbPassword;
private $tablePrefix;
private $dbport;
function __construct($ndbhost = "localhost", $ndbname = "", $ndbusername = "", $ndbuserpassword = "", $ndbtableprefix = " ", $ndbport = 3600){
  //default Constructor
  $this->host = $ndbhost;
  $this->dbName = $ndbname;
  $this->dbUser = $ndbusername;
  $this->dbPassword = $ndbuserpassword;
  $this->tablePrefix = $ndbtableprefix;
  $this->dbport = $ndbport;

  echo $this->host . ',';
  echo $this->dbName . ',';
  echo $this->dbUser . ',';
  echo $this->dbPassword . ',';
  echo $this->tablePrefix . ',';
  echo $this->dbport;

  parent::__construct($this->host, $this->dbName, $this->dbUser, $this->dbpassword, $this->tableprefix, $this->dbport);
  $this->dbC = parent::getdbconnection();
}

该模型

//model.php
require("./Class/Database.php");
require("./Class/QueryBuilder.php");
$result=false;
$host = '192.168.1.2'; //or localhost , same thing, also tried 127.0.0.1
$database = 'phpclasses';
$dbuser = 'phpClasses';
$dbuserpw = 'test1234';
//now I want to see that the connection has been made.
//$db = new DatabaseClass($host, $database, $dbuser, $dbuserpw);
$qb = new QueryBuilderClass($host, $database, $dbuser, $dbuserpw);

我感谢大家的时间和您的帮助;

杰西·芬德

在孩子。 $ this-> dbpassword与$ this-> dbPassword的拼写错误。 与$ tablePrefix和$ tableprefix相同

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM