Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-07-24, 11:55 PM
Junior Member
 
Join Date: Jul 2008
Posts: 1
icelandic is on a distinguished road
Default connecting to MySQL through ssh2_tunnel

I'm trying to connect one linux server to another linux server's mysql db using the PHP function ssh_tunnel().

Background:
I can access the linux server's mysql db on my Mac by typing in the command line:

Code:
ssh username@serverIP -L 3307:192.168.0.100:3307
Then I use CocoaMySQL to access the DB.

Current:
I want to do about the same thing with PHP to connect one linux server to the other linux server's mysql db. Here's what I've tried:
PHP Code:
$connection ssh2_connect('serverIP'22);
if (
ssh2_auth_password($connection'username''secret')) {
  echo 
"Authentication Successful!\n";
} else {
  die(
'Authentication Failed...');
}
print
"<br><br>";
if(
function_exists("ssh2_tunnel"))
 echo 
"success";
else
 echo 
"failure";
print
"<br><br>";
$tunnel ssh2_tunnel($connection'192.168.0.100'3307);
 
$conn mysql_connect('127.0.0.1''DBusername''DBpassword' ) or die (mysql_error()); 
The ouput I get is:

HTML Code:
Authentication Successful! 
 
success
 
Access denied for user 'DBusername'@'localhost' (using password: YES)
But If I change the username and password to the local mysql username and password, then I get access to the local mysql db but not the remote mysql db.

Any ideas how to connect to the remote server, through ssh, and use the mysql_connect() function?
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:46 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.