Make sure MySQL has enabled outside access, you probably don't have access from remote machines to the VPS.
UPDATE: Do you have access to phpmyadmin or a tool like that?
Domanda
I want to connect to a VPS server with the following code. What is wrong with it?
<?php
$con = mysqli_connect("A.B.C.D", "user", "pass", "db1");
if (!$con) {
die("Could not connect: ".mysqli_errno());
}
$sql = "SELECT * FROM table1";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
extract($row);
echo $name;
?>
The above code gives the error : Could not connect:
However, when I use "localhost" and run this script on a copy of that database and table that I have in my laptop, it runs smoothly and echoes the name from the first record in the table.
Why am I not being able to connect to my VPS?
Soluzione
Make sure MySQL has enabled outside access, you probably don't have access from remote machines to the VPS.
UPDATE: Do you have access to phpmyadmin or a tool like that?
Altri suggerimenti
Check the following;