来自 php 的 MySQLi 访问被拒绝

MySQLi access denied from php

当我尝试在 PHP 中连接 MySQLi 时,出现以下错误:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in xxxxxxxx

Connect Error (1045) Access denied for user 'root'@'localhost' (using password: YES)

但是我可以使用完全相同的凭据登录到 phpmyadmin 并使用 mysql 控制台。

我已经授予 root@localhost 所有权限。

这是我用来连接数据库的测试文件:

<?php

$mysqli = new mysqli('localhost', 'root', 'rootPassword', 'myDatabase');

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error );
}
echo 'Connection OK';
$mysqli->close();
?>

我应该怎么做才能解决这个问题?

更新:

这是新代码:

$mysqli = new mysqli('localhost', 'root', 'root', 'ignis', '3307');

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error );
}
echo 'Connection OK';
$mysqli->close();

有了这个我得到了连接正常,但是当我尝试使用连接到数据库的 'joomla' 方式连接时我仍然得到错误

Error displaying the error page: Application Instantiation Error: Could not connect to MySQL.

有人知道如何解决这个问题吗?

这是我的 configuration.php 文件中用于连接数据库的部分:

public $dbtype = 'mysqli';
public $host = 'localhost:3307'; 
//tried using :59420 no success either but i have configured it
//to port 3307 in wamp so idk how the mysql console ever came up with port 59420.
public $user = 'root';
public $password = 'root';
public $db = 'ignis';
public $dbprefix = 'igns_';

show processlist

的结果
+----+------+-----------------+------+---------+------+----------+------------------+
| Id | User | Host            | db   | Command | Time | State    | Info             |
+----+------+-----------------+------+---------+------+----------+------------------+
| 85 | root | localhost:59420 | NULL | Query   |    0 | starting | show processlist |
+----+------+-----------------+------+---------+------+----------+------------------+

折腾了一天终于弄明白了,

joomla 对它使用的文件很奇怪,它更喜欢 joomla 文件夹中的 configurations.php.txt,高于站点根目录中的 configurations.php。

为什么?

因为在factory.php文件中有这样一段代码:

public static function getConfig($file = null, $type = 'PHP', $namespace = '')
    {
        if (!self::$config)
        {
            if ($file === null)
            {
                $file = JPATH_CONFIGURATION . '/configuration.php.txt'; 
            }

            self::$config = self::createConfig($file, $type, $namespace);
        }
        return self::$config;
    }

其中 JPATH_CONFIGURATION = JPATH_ROOT(joomla 文件夹) /configuration.php.txt 是硬编码的,所以它忽略了 /configurations.php 文件。

但我仍然不明白为什么 mysql 在 windows 更新后突然中断?是因为有一个更新与阻止没有指定端口的连接有关吗?因为这在 windows 更新之前有效。