Reputation: 25584
I have an hosting account with PostgreSQL and PHP. I need to access to an PostgreSQL Database, those Database is only accessible from outside via SSH.
How can I communicate with the PostgreSQL using PHP? What are my best options?
Can someone give me a clue?
Can I use for example something like this? http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
Best Regards,
Upvotes: 0
Views: 3265
Reputation: 9671
Once you've set up the tunnel, you connect to your database via 127.0.0.1. e.g. (MySQL Example):
ssh -L 127.0.0.1:3307:127.0.0.1:3306 [email protected]
After that the connection parameters for my database are:
Host: 127.0.0.1 (localhost would try to connect to socket)
Port: 3307
User: DatabaseUser
Pass: DatabasePass
Upvotes: 1
Reputation: 2499
You can use putty to ssh into your server and from there you can run postgreSQL, here some help running postgreSQL from a command line: http://www.postgresql.org/docs/8.3/static/app-psql.html
Or you can use a tool like phpmyadmin but to configure postgreSQL called phpPgAdmin: http://phppgadmin.sourceforge.net/doku.php
Hope this helps you a bit :)
Upvotes: 0
Reputation: 86
After setting up the database, you should be able to interact with it using built-in methods that PHP provides:
For reference and tutorials, check out: http://www.php.net/manual/en/book.pgsql.php
Upvotes: 0