php拒绝访问MySQLi


MySQLi access denied from php

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

警告:mysqli::__construct():(HY000/1045):用户'root'@'localhost'访问被拒绝(使用密码:YES)在xxxxxxxx

连接错误(1045)用户'root'@'localhost'访问被拒绝(使用密码:YES)

然而,我可以用完全相同的凭据登录到phpmyadmin和使用mysql控制台。

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

下面是我用来连接数据库的testfile:

<?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();

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

显示错误页面: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;
    }

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

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