Connect Error with mysqli

时光怂恿深爱的人放手 提交于 2019-12-02 02:29:17

问题


I have a page navigation script that returns 65 records per page on my web site. It used to work fine until my hosting provider moved me to a different server. Now when I go to the page, I get the following error:

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

Line 34 of page.php:

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];
        }

Obviously, I have the correct login credentials filled in to connect to the database, but it seems to be ignoring them and trying to login with root as the username.

Is this an issue with my hosting provider and how they have the server set up??


回答1:


Since you are using the MySQLi constructor there is no need to use the connect() method since it will automatically connect to the database.

Remove this line and it should work...

Line 10: $db->connect();



回答2:


Yeah, as per the commenter, I'd drop the ->connect() call. It's what's breaking your code. And switch to localhost, so it uses sockets instead of IP connection.



来源:https://stackoverflow.com/questions/13975659/connect-error-with-mysqli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!