Dave's Brain

Browse - programming tips - perl dbi get error string

Date: 2008jun19
Language: perl
Platform: DBI

Q.  How do I know what went wrong with my sql query?

A.  Perl's DBI has *three* function for you:

	$number = $dbh->err();		# Gets the error number
	$str = $dbh->errstr();		# In english
	$str = $dbh->state();		# SQL 5 character code

Notice that they require a handle so what to do when a connect()
fails and you don't get a handle?  In that case use:

	$number = DBI::err();		# Gets the error number
	$str = DBI::errstr();		# In english
	$str = DBI::state();		# SQL 5 character code
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: