Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If PHP installation is missing PostgreSQL support, the error message is not clear #875

Closed
wesyah234 opened this issue Sep 15, 2022 · 7 comments
Labels
pgsql PostgreSQL (Tier 1) wontfix

Comments

@wesyah234
Copy link
Contributor

We moved code to a new server, and the PHP on that server was missing PostgreSQL support. The error number we received was -24 and the error message was also -24. Is there anything else we could be doing to make troubleshooting more efficient? We didn't immediately think "oh, the PostgreSQL support is missing", rather we were looking at the database, the firewall, etc wondering why it would not connect.

@dregad
Copy link
Member

dregad commented Sep 15, 2022

Yes that makes sense, I'll look into it

@dregad
Copy link
Member

dregad commented Sep 16, 2022

@wesyah234 I'll need you to provide a bit more context on that one. In particular, what do you mean exactly by server was missing PostgreSQL support, and what code did you run to get this -24 error message ?

I tried to reproduce this on my dev box, by disabling the pgsql extension and trying to connect.

$db = NewADOConnection('pgsql');
$db->debug=true; 
$res = $db->connect($host, $user, $password, $database);
var_dump($res); // false
echo "{$db->ErrorMsg()} ({$db->ErrorNo()})\n"; // Database connection failed (-1)

If you use exceptions, the connect() statement will throw

Fatal error: Uncaught ADODB_Exception: postgres9 error: [0: Missing extension for postgres] in CONNECT(localhost, 'root', '****', test) in /home/dregad/dev/adodb/adodb-exceptions.inc.php on line 86

If not, with debug mode ADOdb prints

localhost: Missing extension for postgres

Considering the error's severity, maybe it would make sense to display the error also when debug mode is false.

But in any case, connect() returns false - are you not checking that in your code ? You should.

If you continue anyway after the failed connect statement and try to execute a query, PHP chokes with

Fatal error: Uncaught Error: Call to undefined function pg_query()

Which IMO makes the problem quite obvious.

With regards to the -24 error code, this is defined as a constant in adodb-error.inc (DB_ERROR_CONNECT_FAILED). so I assume you included that in your code. In this case, you'd need to call $db->metaErrorMsg($db->errorNo()) to get the portable error message (connect failed in this case).

@dregad
Copy link
Member

dregad commented Sep 22, 2022

@wesyah234 any feedback ?

@wesyah234
Copy link
Contributor Author

Yes, sorry, I was putting together some tests. Here are my comments so far:

I'm not using exceptions (as the code is pretty old and was written before php had exception support), so as you said, I would not have seen the "missing extension" message unless I turned on debug mode. And I agree with you, it would be great to have that message emitted somehow even without debug on.

I am checking the connect return value, and then going after the db error number and error message, which are "-1" and "database connection failed" the first time, but then my code automatically tries a few more times, and repeated connection attempts then emit the -24 error code, so that is a bit weird that it changes...

I might consider switching over to exception handling...

In the meantime, for code not using exceptions, would you consider:

  1. emitting that missing extension message regardless of debug mode
  2. possibly adding something about missing extension into the db error message (since that only says "database connection failed" and doesn't mention the extension issue.

Thanks for the quick and detailed response!

@dregad
Copy link
Member

dregad commented Sep 23, 2022

then my code automatically tries a few more times, and repeated connection attempts then emit the -24 error code, so that is a bit weird that it changes...

I agree that it's weird, we should have consistent behavior.

Could you provide a code snippets to reproduce what you do in the tries a few more times bit, leading to the error number changing from -1 to -24 ? Because when I retry the connect(), I still get -1...

$res = $db->connect($host, $user, $password, $database);
echo "{$db->ErrorMsg()} ({$db->ErrorNo()})\n"; // Database connection failed (-1)
$res = $db->connect($host, $user, $password, $database);
echo "{$db->ErrorMsg()} ({$db->ErrorNo()})\n"; // Database connection failed (-1) <- not -24

In the meantime, for code not using exceptions, would you consider:

  1. emitting that missing extension message regardless of debug mode

Yes, definitely.

In fact, I think it even makes sense to just die() in this case, as clearly the code cannot continue.

  1. possibly adding something about missing extension into the db error message (since that only says "database connection failed" and doesn't mention the extension issue.

That might be a bit complicated to implement, need to check.

@yodatak
Copy link

yodatak commented Oct 9, 2022

Hi on a fresh postgresql 13 nginx and php 8 on a redhat 8 i got the same issue when trying to installing a mantis the -24 error

@mnewnham
Copy link
Contributor

As there has been no additional feedback or discussion on this i'm closing this as ''wontfix''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pgsql PostgreSQL (Tier 1) wontfix
Projects
None yet
Development

No branches or pull requests

4 participants