0

Why doesn't this code work in a model in codeigniter. It works perfectly in "normal" php (with the same variables for the connection).

$con = pg_connect("host=$host dbname=$db user=$user password=$pass")
                or die ("Could not connect to server\n"); 

The following error pops up after some amount of time:

Message: pg_connect(): Unable to connect to PostgreSQL server: could not connect to
server: Connection timed out Is the server running on host "198.xxx.xxx.xxx" and accepting 
TCP/IP connections on port 5432?

The answer to this, is as I know, yes

10
  • Btw, I have tried connecting to multiple databases following various tutorials, it does not work, but I get other errors. I am connecting to this external database to fetch some data from a sister site. Commented Feb 19, 2014 at 23:52
  • When you say it works in "normal" PHP, is this ran on the same server as Codeigniter with the errors? Commented Feb 19, 2014 at 23:52
  • No, another server. However, on the CI server, I have the option to use a postgres database, so would it not be fair to assume the server can handle this? Do you have something else in mind? Commented Feb 19, 2014 at 23:54
  • Try the "normal" php script on the CI server (but outside of the CI installation). If it doesn't work, then your database server isn't allowing access from the CI server. Commented Feb 19, 2014 at 23:57
  • I'm thinking that the remote PostgreSQL server you are connecting to has restricted access (possibly only localhost, or specific IPs). This is default activity for security reasons. Check this question. Commented Feb 19, 2014 at 23:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.