Solved

Perl, Postgres, Get error message from data base call

Posted on 2010-09-21
3
430 Views
Last Modified: 2012-05-10
How do I get  the error message from data base call.  For example, $num1 and $num2 was supposed to have interger, but instead I assigned it a string, which will cause a database error.

  $dbh = DBI->connect("dbi:Pg:dbname=mis;host=$gHost", "$gUser", "$gPassword", { RaiseError => 0, AutoCommit => 1 });
  $sth = $dbh->prepare("insert into myTable(a,b) values ('$num1','$num2',);");
  $sth->execute();
  if( $DBI::err ) {
    #How do I get the database error message?
  } else {
    $success = 1;
  }
0
Comment
Question by:rgbcof
3 Comments
 
LVL 15

Accepted Solution

by:
ishando earned 125 total points
Comment Utility
$sth->err()
 $sth->errstr()
 
 These give the error number and error message for oracle. As these are DBI attributes and not DBD they should also work for postgres
 
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 125 total points
Comment Utility
You could also use the variable $DBI::errstr, or call err() and errstr() on the $dbh.
0
 

Author Closing Comment

by:rgbcof
Comment Utility
They both came up with the right solution.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now