LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2004, 02:06 AM   #1
w0000422
Member
 
Registered: Dec 2003
Distribution: redhat linux 9.0
Posts: 60

Rep: Reputation: 15
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);
?>
 
Old 01-13-2004, 07:08 AM   #2
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Ubuntu, RHEL, CentOS, MacOS
Posts: 39

Rep: Reputation: Disabled
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"
 
Old 01-13-2004, 06:46 PM   #3
w0000422
Member
 
Registered: Dec 2003
Distribution: redhat linux 9.0
Posts: 60

Original Poster
Rep: Reputation: 15
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
 
Old 01-15-2004, 01:55 AM   #4
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Ubuntu, RHEL, CentOS, MacOS
Posts: 39

Rep: Reputation: Disabled
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.

Last edited by Ashkhan; 01-15-2004 at 04:45 AM.
 
Old 01-15-2004, 08:39 AM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
Old 01-15-2004, 06:33 PM   #6
w0000422
Member
 
Registered: Dec 2003
Distribution: redhat linux 9.0
Posts: 60

Original Poster
Rep: Reputation: 15
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Restoring Mysql Databases davethegenius Linux - Software 2 08-05-2005 02:01 PM
Can i connect to MySQl databases through Telnet? Santorres Linux - Networking 2 01-27-2004 07:04 AM
Comparing two MySQL Databases WeNdeL Linux - Software 1 09-30-2003 03:47 PM
restoring mysql databases? and mysql permissions... armegeden Linux - Software 0 03-13-2003 11:04 AM
mysql databases k3v0 Linux - Software 2 12-03-2002 07:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration