Report this

What is the reason for this report?

Cannot connect to MySQLi?

Posted on January 2, 2017

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?



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.