NameSilo

Connecting to a database on another host

Spaceship Spaceship
Watch
Impact
19
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
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
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_info/mysql/mysql_usertable.shtml

PHP:
<?php
// we connect to example.com and port 3307
$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);
?>
 
2
•••
okiee got it:D thanks +Rep
 
0
•••
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
 
0
•••
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
 
0
•••
Great Question And Response :D (Bookmarked and Rep+)
 
0
•••
baxter said:
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).

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
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back