NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Connecting to a database on another host

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 01-08-2007, 06:36 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

Connecting to a database on another host


Hey
I want to code php and run it on my desktop [i have everything installed and working] but i want to use the db that is on my site..so that i dont have to backup and import the db everytime i am done for the day...
Is there any way of connecting to my sites db through php which is not on that same domain/site at the moment?
thanks
unknowngiver is offline  
Old 01-08-2007, 07:13 PM   #2 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 360
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
sure can.

taken from http://www.php.net/mysql_connect change example.com to your website and 3307 to your mysql port number. Also make sure you've enabled mysql to accept connection from other domains. Which in phpmyadmin is in Privledges for your user change it to your home ip or % for a wildcard, which isn't really a great idea todo.

this is also a fairly older tutorial but seems to have the information you need.

http://webmaster.iu.edu/tool_guide_i...sertable.shtml

PHP Code:
<?php
// we connect to example.com and port 3307
????: NamePros.com http://www.namepros.com/programming/278842-connecting-to-a-database-another-host.html
$link mysql_connect('example.com:3307''mysql_user''mysql_password');
if (!
$link) {
   die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';
mysql_close($link);

// we connect to localhost at port 3307
$link mysql_connect('127.0.0.1:3307''mysql_user''mysql_password');
if (!
$link) {
   die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';
mysql_close($link);
?>
__________________
Canadian Domain Registrar Ready.ca
baxter is offline  
Old 01-08-2007, 08:34 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
okiee got it thanks +Rep
unknowngiver is offline  
Old 01-08-2007, 08:36 PM   #4 (permalink)
New Member
 
frankr's Avatar
Join Date: Dec 2006
Location: Atlanta, GA
Posts: 14
frankr is on a distinguished road
 



If you are connecting to a database over the internet, it is a good idea to consider using SSH port forwarding to allow for strong authentication and encryption of the data in transit.

Frank
__________________
Software Developer, www.peachtreecommunication.net.
Director of Membership, Metro Atlanta ISSA.
Author of SQL Converter for Excel, which is an Excel add-in for converting data to MySQL.
frankr is offline  
Old 01-09-2007, 07:00 AM   #5 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 360
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
Hey Frank,

I have never thought of doing that before, Is there much in the way of decrease in performance/speed? Do you have any tutorials on the concept and setup?

Cheers,

Baxter
__________________
Canadian Domain Registrar Ready.ca
baxter is offline  
Old 01-09-2007, 08:13 AM   #6 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 390
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Great Question And Response (Bookmarked and Rep+)
beaver6813 is offline  
Old 01-09-2007, 09:46 AM   #7 (permalink)
New Member
 
frankr's Avatar
Join Date: Dec 2006
Location: Atlanta, GA
Posts: 14
frankr is on a distinguished road
 



Originally Posted by baxter
I have never thought of doing that before, Is there much in the way of decrease in performance/speed? Do you have any tutorials on the concept and setup?
While there has to be a slowdown due to the time to encrypt and encapsulate the communications, the delay is not noticeable for the applications I use. I regularly SSH port forward MySQL and Windows Remote Desktop (RDP).
????: NamePros.com http://www.namepros.com/showthread.php?t=278842

I do not know of a tutorial, but the setup is straight forward. You configure your SSH client to listen on a particular port on your localhost and pipe that to a particular port at the remote side.

For example, if I do not have a MySQL server on my local machine I could port forward 3306 to example.com:3306. 3306 could even be fire-walled on the remote side and as long as SSH is allowed through the connection can work.

The destination does not even have to be on the same machine as the SSH server. It makes for a very flexible VPN solution.

Frank
__________________
Software Developer, www.peachtreecommunication.net.
Director of Membership, Metro Atlanta ISSA.
Author of SQL Converter for Excel, which is an Excel add-in for converting data to MySQL.
frankr is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:18 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger