Alexis Zenigata
Alexis Zenigata

Reputation: 165

Connecting to a remote database from a localhost computer using mysql and PHP

So here is the situation. I have a database on a remote server that gives out quizzes and scores for individual students...

I also have a local database which contains the students names and their respective groups.

What I want to do is to display the list of students per group then show the results of their scores from the remote database.. Is this possible??

Im currently running the script from my local computer using XAMMP like so mysql_connect("REMOTE SERVER ADDRESS","USERNAME", "PASSWORD") or die("Could not connect to MySQL server!");

But all I get is Could not connect to MySql Server..

Upvotes: 6

Views: 17435

Answers (2)

Avinda
Avinda

Reputation: 86

https://documentation.cpanel.net/display/ALD/Remote+MySQL# I found useful this one myselt. When you haven't define access permissions to remote db using it's cpanel, then you cannot connect with it via the localhost from your PC.

You will find something like 'Add Access Host' in your hosting server cpanel and there you can add which IPs are you going to use to access from outside. There I used as "%.%.%.%" and that means I allowed every v4 IPs to access my database. Instead of "%.%.%.%" you can put your PC's IP(for example 51.254.230.178). As PC's IP gets changed frequently, then I used this because I cannot change it manually all the time by checking my IP every time I connected to the Internet.

Upvotes: 1

Cyclonecode
Cyclonecode

Reputation: 29991

GRANT ALL ON database.* TO user@ipaddress IDENTIFIED BY 'password';

You should force a reload of the grant tables using:

FLUSH PRIVILEGES;

Upvotes: 5

Related Questions