[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Perl, Postgres, Get error message from data base call

Posted on 2010-09-21
3
Medium Priority
?
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

656 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