MSUK1 Posted December 1, 2010 Share Posted December 1, 2010 i tried googling but didnt really know how to "google it" as i cant think of a short phrase that best describes it.. but i want to chance the database setting of "localhost" in my php script to another websites database how do i acheive this? Quote Link to comment https://forums.phpfreaks.com/topic/220383-define-another-database/ Share on other sites More sharing options...
Eiolon Posted December 1, 2010 Share Posted December 1, 2010 If you are trying to connect to an external database, permissions must be set on that database to allow access. For example, with MySQL, you could need to grant access: GRANT ALL PRIVILEGES ON db_name.* TO username@'IP_ADDRESS_HERE' IDENTIFIED BY 'password_here'; Then you create a new database connection using the above information. EDIT: Forgot to mention if they are not using the default MySQL port you will need to define that as well. Quote Link to comment https://forums.phpfreaks.com/topic/220383-define-another-database/#findComment-1141924 Share on other sites More sharing options...
MSUK1 Posted December 1, 2010 Author Share Posted December 1, 2010 what IP address is that exactly, lets say we have SERVER 1 & SERVER 2 server 1 holds the data server 2 connects to server 1 for the data so whose who in that situation? sorry this part really baffles me, using localhost and keeping it all internal, no problem for me, but its vital that we get an external connection :/ thankyou" Quote Link to comment https://forums.phpfreaks.com/topic/220383-define-another-database/#findComment-1141933 Share on other sites More sharing options...
Eiolon Posted December 1, 2010 Share Posted December 1, 2010 The IP is of the connecting server, so in your scenario, SERVER 2. You may need to edit your config file to make sure the MySQL server is listening to the SERVER 2 IP. By default I think it only listens to localhost. Quote Link to comment https://forums.phpfreaks.com/topic/220383-define-another-database/#findComment-1141940 Share on other sites More sharing options...
MSUK1 Posted December 1, 2010 Author Share Posted December 1, 2010 i have cpanel so i edited the remotesql and added SERVER2 and in the php script i have this... <?php $host="174.37.172.25"; // Host name $username="db_System"; // Mysql username $password="password"; // Mysql password $db_name="table_StaceyOfficialLoginSystem"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 1;"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> Quote Link to comment https://forums.phpfreaks.com/topic/220383-define-another-database/#findComment-1141973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.