简体   繁体   中英

Connect Oracle DB with port forwarding using PHP

I want to connect to Oracle database, which requires port forwarding, using PHP. Here is the setup. Currently i use PuTTy to connect to Oracle Db. There i feed

Host ip: 172.XX.XX.111 port:22

Tunnel setting Source port : L19005

Destination : 172.XX.XX.40:1521

After entering userid/password,i am able to connect sqldeveloper which needs TNS config.

Now i want to perform same activity using PHP. Here's what i have done so far

set_include_path(get_include_path().'\phpseclib');
include('Net/SSH2.php');

$ssh = new Net_SSH2('172.XX.XX.111');
if (!$ssh->login('userid', 'password')) {
    exit('Login Failed');
}
$ssh->write("ssh -L19005:172.XX.XX.40:1521 172.XX.XX.111\n");
$ssh->write("password\n");

$connect='(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=19005))(CONNECT_DATA = (SID = connect)))';
$conn = oci_connect('Db_username', 'Db_password', $connect);
if ($conn)
{echo 'True';}

I also used ssh2_connect function.

$connection = ssh2_connect('172.XX.XX.111', 22);
if (ssh2_auth_password($connection, 'userid', 'password'))
{
echo 'true';
}
ssh2_exec($connection,"ssh -L19005:172.XX.XX.40:1521 172.XX.XX.111","\n");
ssh2_exec($connection,"password","\n");

$connect='(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=19005))(CONNECT_DATA = (SID = connect)))';
$conn = oci_connect('Db_username', 'Db_password', $connect);
if ($conn)
{echo 'True';}

In both the cases, i am getting the following error.

oci_connect(): ORA-12541: TNS:no listener in C:\xampp\htdocs\USAGE\index.php

I am using XAMPP3.2.2 with PHP5.5.

Please help. I have searched a lot but could not find anything that relates to my issue.

phpseclib doesn't do tunneling. What it looks like you're expecting it to do is for PHP to create a server on port 127.0.0.1:19005 but at that point you'd need an SSH server - not an SSH client.

My recommendation: use autossh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM