Error connecting to mysqli

I have a navigation page script that returns 65 entries per page on my website. It worked fine until my hosting provider moved me to another 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 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 credentials to log in to the database, but they seem to ignore them and try to log in with the username root.

Is this a problem for my hosting provider and how do they have a server installed?

+2
source share
2 answers

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

Delete this line and it should work ...

 Line 10: $db->connect(); 
+1
source

Yes, according to the commentator, I would drop the call โ†’ connect (). This is what breaks your code. And switch to localhost, so it uses sockets instead of an IP connection.

0
source

Source: https://habr.com/ru/post/1491432/


All Articles