php - 错误 1045 : access denied for user 'root' @'localhost' using password NO. .. 通过扩展类连接时,其他

标签 php mysql

我有一个类可以毫无问题地连接到数据库。在扩展该类时,相同的连接失败。凭证在 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;
}
}

现在的 child

//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);

感谢大家的宝贵时间和帮助;

杰西芬德

最佳答案

在 child 身上。 $this->dbpassword 与 $this->dbPassword 有大小写混合拼写错误。 $tablePrefix 与 $tableprefix 相同

关于php - 错误 1045 : access denied for user 'root' @'localhost' using password NO. .. 通过扩展类连接时,其他,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43221938/

相关文章:

javascript - 使用两个按钮发布或显示选择的表单数据

PHP mysqli_fetch_assoc() 函数在同一个 PHP 文件工作时返回 NULL

php - 有没有办法在 php 中定义全局或标准函数,可以从任何地方调用而不包含文件

php - 同一 MySQL 列中的阿拉伯语和英语混淆了

mysql - 改变查询结果

MySQL:在子查询的 WHERE 语句中使用 CONCAT() 作为列名

mysql - 如何在 mysql 中只允许字母数字值

php - 选择重复记录,其中一条记录必须包含准确的值

php - mongodb在php中对聚合进行排序

php - 带有特殊字符 æøåü 等的 stristr