连接错误使用的mysqli(Connect Error with mysqli)

2019-07-17 11:09发布

我有一个页面导航脚本返回我的网站上共有65条记录每页。 它用来做工精细,直到我的托管服务提供商,让我感动到不同的服务器。 现在,当我去的网页,我得到以下错误:

Warning: mysqli::connect() [mysqli.connect]: (28000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /home/jumbleweed/public_html/registry/browse_2004.php on line 10

Warning: mysqli::query() [mysqli.query]: invalid object or resource mysqli in /home/jumbleweed/public_html/registry/page.php on line 34

Line 9:  $db = new mysqli('localhost', 'my_username', 'my_password', 'my_database');
Line 10: $db->connect();

page.php文件的第34行:

public function countRecords() {
            //returns the number of records
            global $db;
            $count_query = "SELECT COUNT(*) FROM (".$this->query.") as temp";
Line 34:    $result = $db->query($count_query);
            $row = $result->fetch_row();
            return $row[0];
        }

很显然,我已经填充了连接到数据库的正确的登录凭据,但它似乎是忽略了他们,并试图用root作为用户名登录。

这是我的托管服务提供商,以及它们如何在服务器设置的问题?

Answer 1:

由于您使用的是MySQLi的构造就没有必要使用connect()方法,因为它会自动连接到数据库。

删除此行,它应该工作...

Line 10: $db->connect();


Answer 2:

是的,按照该评论者,我会放下 - > connect()调用。 这是什么破你的代码。 并切换到本地主机,所以它使用的,而不是IP连接插座。



文章来源: Connect Error with mysqli