1

I am used to Perl "crashing" my script when a SQL goes bad, but Postgres is just giving the error to the Apache error log and the script continues. Evil behaviour for debugging code.

Now I have asked the Oracle of Google but either I am asking the wrong questions or, very unlikely, I am the only one with that problem. ;)

In Short: I want the same fault behaviour with Postgres as MySQL does, ie, "crash" the script and take heed of use CGI::Carp qw(fatalsToBrowser); and just show me the faulty SQL statement.

I am using good old DBI to access the PG-DB, Postgres 8.4 and Perl 5.10.1 on Ubuntu 10.04 on my server, if that matters. All packages are from the official rep.

EDIT: Thanks to Richard Huxton this is solved, leaving the solution for others to find.

our $dbh = DBI->connect($DBUrl, $DBUser, $DBPass,{ RaiseError => 1}
           ) || die "Could not connect to database: $DBI::errstr";
0

1 Answer 1

1

Surely you just need to set RaiseError when you make the connection?

https://metacpan.org/module/DBI

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

3 Comments

Thanks, that was it. No clue why that is the default behaviour with MySQL but not with Postgres.
I didn't think it was on by default with any DBI driver. Docs seem to suggest off is the default
Nope, never defined that when using MySQL. Very strange indeed. o.o

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.