Question

Cannot connect to MySQLi?

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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");
}