By krismantotan
Hi.
How can I connect to DigitalOcean’s managed databases from PHP 5.6? I’m running a vps on CWP and I can’t seem to get it right.
$info = [
"address" => "xxxxxxxxxxxxxxxxxxxxxxx.db.ondigitalocean.com",
"user" => "db_user",
"pass" => "db_pass",
"db" => "db_name",
];
$link = mysqli_init();
if (!$link) {
die('mysqli_init failed');
}
if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
if (!mysqli_real_connect($link, $info["address"], $info["user"], $info["pass"], $info["db"], '25060')) {
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
echo 'Success... ' . mysqli_get_host_info($link) . "\n";
mysqli_close($link);
?>```
$info["user"]'s host is set to my VPS's ip address.
$info["user"]'s is granted to access $info["db"].
$info["pass"] was created with IDENTIFIED WITH mysql_native_password.
But I'm keep getting error "Connect Error (2002) Connection refused."
http://testdb.fscchan.nl/connecttodb.php
I'm running PHP 5.6 on CWP.
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!
Hi @krismantotan,
There is a very good YouTube video made from one of the community managers which you can watch and help you with your issues - https://www.youtube.com/watch?v=EAZoXK3i7eA&t=133s
Please watch it and see if it would help you out in your problems.
Regards, KDSyS
Hi KDSys, I just upgrade my PHP to PHP 7.3 but error message still : Connection refused
Maybe port 25060 should be opened in hosting/client.
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.