Hello DigitalOcean community,
I’ve finally hosted my php files on my webhost, but now I’ve ran into an issue with MySQLi. When I try to connect to it, I get an error. Below is the code I’m using to connect:

$Connect = new mysqli("http://159.203.111.##/", "root", "########", "log_db");
if ($Connect->connect_error) {
     die("An error has occurred while connecting to the host");
}

This always returns “An error has occured while connecting to the host”. I can also connect to “159.203.111.##/phpmyadmin” with those passwords aswell. I’m using WAMP and PHP to do this.

Does anyone know the issue?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Code looks like you are trying to connect over http to your database. This is probably root of issue, try removing it.
After removing code will be something along:

$Connect = new mysqli("159.203.111.##", "root", "########", "log_db");
if ($Connect->connect_error) {
     die("An error has occurred while connecting to the host");
}

If issue still persist, change IP address to localhost if database is on same server:

$Connect = new mysqli("localhost", "root", "########", "log_db");
if ($Connect->connect_error) {
     die("An error has occurred while connecting to the host");
}
Submit an Answer