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!
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");
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.