Reputation: 410
I'm new to MySQL
and PHP
and using 5.0 version of php. My requirement is to connect to a MySQL
database which is located on another server (www.some-domain.com). My PHP
files are located in my local system.
I have remote server database
credentials. How do I configure these details into the PHP
file ?
Here is my code so far:
mysql_connect("remote server ip", "root", "root123") or die (mysql_error ());
// Select database
mysql_select_db("resource") or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM resource WHERE resource_type=11";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
when i use above code getting below error:
Access denied for user 'root'@'%' to database 'resource'
Upvotes: 0
Views: 194
Reputation: 12168
There is a possibility, that remote connections are not allowed within MySQL Server access rules, as a common security measure. I suggest you to contact server support team for further details.
Also, I suggest to read this.
Upvotes: 1
Reputation: 856
To connect to your mysql database in another server, you need to get the host, username and password of the database on that particular server. Like,
mysql_connect('server_host', 'server_db_username', 'server_db_password');
mysql_select_db('server_db_name');
Your code is correct. You only need to connect with the server credentials.
Upvotes: 1