I'm busy trying to connect to a PostgreSQL database (running on a different server) after creating an ssh2_tunnel to that server.
The ssh2_tunnel seems to be working fine but my pg_connect is not working and I'm hoping I'm missing something small
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
echo "<span>test script<br /></span>";
$connection = ssh2_connect('xxx.xx.xx.xx', 22);
if (ssh2_auth_pubkey_file($connection, 'usname', './ssh_key.pub', './ssh_key', 'psword')) {
echo "<span>Public Key Authentication Successful<br /></span>";
} else {
die('Public Key Authentication Failed');
}
if ($tunnel = ssh2_tunnel($connection, '127.0.0.1', 5432)) {
echo "<span>Tunnel Successful<br /></span>";
} else {
die('Tunnel Failed');
};
// this is where it is failing and I'm not sure why
$string = "host=127.0.0.1 port=5432 dbname=dbname user=dbuser password=dbpass";
$pgsqlcon = pg_connect($string) or die('Could not connect: ' . pg_last_error());
?>
It is giving me the following error
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
Another error from pg_last_error
Warning: pg_last_error(): No PostgreSQL link opened yet in /home/shoepack/public_html/admin_php_ssh/notused.php on line 26