Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

php - Accessing DataBases from different servers

I have a network of websites hosted on two different servers, server1 and server2.
I need to be able to access the data stored in a MySQL DataBase on server1 from a PHP script in a site hosted on server2.

Say a user registers on site1 on server1 and his data is inserted into the DataBase on server1. Now, that user would be able to log in on site2 on server2 with the same registration.
That would mean the PHP script on server2 needs access to the MySQL DB on server1. I don't want to copy the user data over to a DB on server2, because the user might also edit his or her user information on site1.

I'd like to be able to share this data without editing the server's data (as in http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html). So far, I haven't been able to figure out a secure way of achieving this, does anyone know how to do this using PHP (or JavaScript, but I'd prefer the system to work for everyone, regardless if JS is enabled)?

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve this by allowing your other servers hostname to connect to your database.

In a MySQL command prompt or phpmyadmin execute the query:

GRANT ALL ON databasename.* TO username@'ipaddress' IDENTIFIED BY 'somepassword';

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...