[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Perl, Postgres, Get error message from data base call

Posted on 2010-09-21
3
Medium Priority
?
446 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 500 total points
ID: 33731275
$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 500 total points
ID: 33731305
You could also use the variable $DBI::errstr, or call err() and errstr() on the $dbh.
0
 

Author Closing Comment

by:rgbcof
ID: 33774337
They both came up with the right solution.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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.
Six Sigma Control Plans
Suggested Courses

830 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