2

I have an issue with previously working script and I don't understand what is happening.

To make it simple I have a html dashboard. This dashboard call php script like this

var jsonData = $.ajax({
      url: "script/pgResumeData.php",
      dataType:"json",
      async: false
      }).responseText;

It was working perfectly until I migrate the machine. I snapshot my volume then reboot on another machine, everything is working except that the pg_connect of the php is not working !

$dbconn = pg_connect("host=127.0.0.1 dbname=test user=user password=pass") or die('Could not connect: ' . pg_last_error());

But if I run my PHP script from the shell "php /.../pgResumeData.php", it's retrieving datas perfectly.

As well the pg_connect return "Query failed:" in the console if I print pg_last_error($dbconn). So seems that I can't get the full error ...

Any idea ?

Edit : Same error if I reach the PHP script with a Browser, but working by shell.

2
  • i don't think you can run javascript from the shell. but i'm not sure. your saying it worked in the past? Commented Apr 20, 2015 at 5:00
  • @AryehArmon I meant run the php script from the shell Commented Apr 20, 2015 at 5:53

3 Answers 3

1

When you say

But if I run my PHP script from the shell "php /.../pgResumeData.php", it's retrieving datas perfectly

You mean on your new machine right ?

I don't know if postgre work like MySQL but maybe some error with the socket, so it will work since the shell know where the socket is but NOT php ?

Try outputting phpinfo() && php.ini to see if the socket is at the right place.

EDIT: Maybe you'll ask yourself why the hell socket would be a problem since i typed 127.0.0.1, well i had the same problem with my MySQL installation where i couldn't connect with localhost/127.0.0.1 but COULD connect with the shell without any problem and had to use the real ip of the machine to connect, it was just a socket problem. So sorry if i'm wrong :p

EDIT n°2: Seems my answer isn't right since you used php ./yourpath.php it should be the exact same output as if it was run in your browser :/ So ... no idea :'(

Sign up to request clarification or add additional context in comments.

1 Comment

Actually whatever I try to do, from apache (javascript calling the php, or the php itself) my pg_connect return false. $dbconn = pg_connect("dbname=test"); var_dump($dbconn); bool(false)
0

Debug the code:

var jsonData = $.ajax({
      url: "script/pgResumeData.php",
      dataType:"json",
      async: false,
      success:function(data) {
        console.log(data) // see the console to see the result
      }
}).responseText;

1 Comment

As i mentioned, the result is "Query failed:" ('Could not connect: ' is use like my copy paste, but I modified to "pg_last_error($dbconn)")
0

I found the problem. It's actually a copy of the following

Can't Connect to PostgreSQL with PHP pg_connect()

To fix it simply do

sudo setenforce 0

That's why it was actually working on the shell but not from apache

Comments

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.