LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to link external databases using mysql? (https://www.linuxquestions.org/questions/programming-9/how-to-link-external-databases-using-mysql-134239/)

w0000422 01-13-2004 02:06 AM

how to link external databases using mysql?
 
hello...i'm design a web site on my local web server but my database is at another site, i know how to use mysql which link to local web server but got no idea how to link it to external database...anyone has this kind of experience?

here is script tat i used to connect to my local database:
<?php
$db_connection = mysql_connect("localhost", "", "")
or die("Could not connect to DB");

mysql_select_db("wsr", $db_connection)
or die("Could not find DB");

$query = mysql_query("select * from cgi", $db_connection);

while($data = mysql_fetch_object($query))
{
print ("$data->name" ."<br>");
}

mysql_close($db_connection);
?>

Ashkhan 01-13-2004 07:08 AM

Just change this line:

PHP Code:

 $db_connection mysql_connect("localhost"""""

Instead of localhost use hostname, then username and password.

PHP Code:

 $db_connection mysql_connect("hostname""username""password"


w0000422 01-13-2004 06:46 PM

i try tat already but won't work and come out the warming like below:

Warning: mysql_connect(): Unknown MySQL Server Host "ITS.com' (2) in /var/www/html/mysql.php on line 2
Could not connect to DB

Ashkhan 01-15-2004 01:55 AM

You can also try this format -
Code:

hostname:port
if your host's db runs on non-standard port.
If you don't succeed then contact your administrator for help.

deiussum 01-15-2004 08:39 AM

Also take a look at the mySQL documentation. Particularly at the GRANT stuff. You'll note that creating a login/password isn't necessarily enough. You may need to create a login/password that works from any hostname.

w0000422 01-15-2004 06:33 PM

i got it, thks a lot!

it can't connect b'cos of the host permission on database center there has not been set...so after i ask for help from support at center there then i able to connect the database.

thks again all of u!


All times are GMT -5. The time now is 02:18 AM.