Connection to a database on an external server
am 13.10.2007 11:49:59 von fleguen
Hi,
I have my own database on a server and the same database on local.
I want to copy all my database from the main server to my local host
(I execute this code from my PC and not my main server)
$id_link_ref = mysql_connect('localhost','database_name','password');
$id_link_local = mysql_connect('localhost','root','password');
it doesn't work :(
Why ? What is the problem ?
Re: Connection to a database on an external server
am 13.10.2007 14:42:18 von Michael Fesser
..oO(Tschuß)
>I have my own database on a server and the same database on local.
>I want to copy all my database from the main server to my local host
>(I execute this code from my PC and not my main server)
>
>$id_link_ref = mysql_connect('localhost','database_name','password');
>$id_link_local = mysql_connect('localhost','root','password');
>
>it doesn't work :(
"Doesn't work" is not really an error description. But your code above
contains several obvious problems:
* The parameters in the first call are wrong. The first parameter is the
server name or address, which should obviously not be 'localhost' if you
want to connect to an external server.
* Running your local database as 'root' is a really bad idea. You should
consider to create a normal user account with restricted permissions for
the daily work. Use 'root' only for maintenance purposes.
* After all connecting to an external database server is often not
possible at all for security reasons. Many hosts allow such access only
from within their own network, not from the outside.
So the better solution is to use the MySQL command line tools to dump
and import the database. Run 'mysqldump' on the server, download the
created dump file and use 'mysql' on your own machine to import it.
If you don't have shell access to the remote machine, see if there's
something like phpMyAdmin available to create the dump. Another possible
way would be to call 'mysqldump' from withing a PHP script and then
download the file.
Micha
Re: Connection to a database on an external server
am 13.10.2007 21:01:47 von gordonb.n27fz
>I have my own database on a server and the same database on local.
Does that mean *TWO DIFFERENT MACHINES*?
Many hosts do not permit database access from arbitrary hosts
for "security reasons".
>I want to copy all my database from the main server to my local host
>(I execute this code from my PC and not my main server)
>
>$id_link_ref = mysql_connect('localhost','database_name','password');
>$id_link_local = mysql_connect('localhost','root','password');
If you are trying to open a connection to two different machines,
shouldn't one of the hostnames NOT be 'localhost'? Also, the second
argument to mysql_connect is a username, NOT a database name,
although they might coincidentally be the same.
>it doesn't work :(
How do you know it failed?
>Why ? What is the problem ?
What was the error message?