开发者

How to communicate with PostgreSQL by SSH via PHP?

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 wi开发者_开发知识库th 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,


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 sshuser@example.com

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


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


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜