0

Hello I have problem with my local computer. I'm install fedora and i have problem to connect with my remote mysql server via php.

php code:

$servername = "my_own_ip";
$username = "test";
$password = "test";
$dbname = "test";

$link = mysql_connect($servername, $username, $password);
if (!$link) {
    die('Could sdf connect: ' . mysql_error());
}

echo 'Connected successfully';

or

$servername = "my_own_ip";
$username = "test";
$password = "test";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();

I'm sure that my server is correct configured, because I'm tested it before on ubuntu, and now I'm test this script on:

http://phpfiddle.org/

And work normally. I think it is a problem with Fedora system, Can you help me ?

bradley546994
  • 630
  • 2
  • 12
  • 30

1 Answers1

0

It's can be couple of issues:

  • Maybe you have a network issue- try to send ping to the server which you want to connect to.
  • Maybe the firewall of your fedora is on. Turn it off:

    $ systemctl disable firewalld

Which error do you get when you run this script?

Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67