Friday, February 18, 2022

[FIXED] Access a MySql Database from PHP (not on localhost)

Issue

there's this server: http://phpmyadmin.pvdata.fr/index.php , I can connect to it knowing the username and password and Server Choice.

Once I connect to it, it shows under MySql the following information: (I'm Translating from French)

Server:  sql6 (sql6 via TCP/IP)
Server Version: 5.0.92-87
Protocol Version: 10
Username: pvdata@10.5.1.3
Character for MySql: UTF-8 Unicode (utf8)

So I tried using the following code in order to connect to the Database:

<?php
// Create connection
$username = "pvdata";
$password = "xxxxxxxx";
$hostname = "10.5.1.3"; 
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
?>

But it didn't work, it's saying: "A connection attempt failed because the connected party did not properly respond after a period of time". What am I doing wrong?


Solution

Go to your phpMyAdmin installation and look for the file config.inc.php. Open that file, and check which hostname / ip is being used for SQL6. That is the IP you should use for your mysql_connect()



Answered By - nl-x

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.