954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

external database connection

Hi guys. I wanted to know if something would be possible. I currently have a server that runs mySQL and i created a database on there for use with PHP-Nuke Treasury module. I don't know much in the way of MySQL besides the basics. I uploaded the .sql file to the database without any problems.

Is there then a way i can connect to this database (say is on oldsite.net) from my other web server (say, newsite.net which is currently without MySQl for a while)?

Lets say the database is called "myDatabase" with user "database" with password "password" given full access privileges. How could i then connect to this database using a script on my newsite.net server?

Any ideas? I tried simple things like oldsite.net as server instead of localhost - but as i said, im new to this MySQL thing.

I also enabled newsite.net to be allowed remote access to oldsite.net - but still wont work

Any questions? Answers? Help? --- much appreciated in advance.

tones1986
Junior Poster
179 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

I dont know if this can help, but read out the user comments in this page.
Cheers,
Naveen

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

I tried the link and it was somewhat useful - but i still couldnt get a connection, if i place the exact same file on the actual server the database is on, the connection works, anywhere else, i cant get a thing working...any more ideas?

tones1986
Junior Poster
179 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

I'm not into PHP but maybe this can help
You can put the IP address of the machine or its name there. However, you must make sure that remote access has been authorized. It is disabled by default.
Secondly there is another postWhen attempting to connect externally to your MySQL server through a database-management software (Such as Navicat or MySQL GUI Tools), you will run into problems being able to connect. Typical error messages include "Lost connection to MySQL server" or "Access Denied", or some other text describing a difficulty in establishing the connection. The reason this happens is because we secure your database access to limit external connections only to IP addresses you've explicitly declared on your External Database IP Access List.
So try to cennect with IP or name of your old domain. If this doesn't work speak with your old provider about DB setup.

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

how do you insert records into the external database? I managed to successfully connect to a second database but I want to be able to insert records into that database from the same page

$dbhost1 = "addresshere";
$dbuser1 = "usernamehere";
$dbpassword1 = "passwordhere";
$db1 = "databasehere";
$connection1 = mysql_connect($dbhost1,$dbuser1,$dbpassword1) or die (mysql_error());
mysql_select_db($db1,$connection1);
 
//MySQL Server 2
$dbhost2 = "addresshere";
$dbuser2 = "usernamehere";
$dbpassword2 = "passwordhere";
$db2 = "databasehere";
$connection2 = mysql_connect($dbhost2,$dbuser2,$dbpassword2) or die (mysql_error());
mysql_select_db($db2,$connection2);


just change the info with the word "here" in it and you done.

And you can link to it like this:

$news = mysql_query("SELECT * FROM tablenamehere",$connection1) or die("State query error!");

$news = mysql_query("SELECT * FROM tablenamehere",$connection2) or die("State query error!");
jaysmoke
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You