Perl DBI does not print error.

S

sam

Hi,

The perl DBI does not prints error message:
$sth = $dbh->prepare($insert_sql)
|| print ERRFILE_OUT "prepare: $insert_sql: $DBI::errstr";

The out of this error only does not print why the error was occurred.
eg.
Unable to execute query: DBI::db=HASH(0x8647df0)->errstr:

Dan anyone please tell me how to prints how a description of the error
from DBI when sql executed failed?

Thanks
Sam
 
X

xhoster

sam said:
Hi,

The perl DBI does not prints error message:
$sth = $dbh->prepare($insert_sql)
|| print ERRFILE_OUT "prepare: $insert_sql: $DBI::errstr";

The out of this error only does not print why the error was occurred.
eg.
Unable to execute query: DBI::db=HASH(0x8647df0)->errstr:

It is not clear whether this is what you want but for some reason you
aren't getting it, or if this is what you get and it is for some reason not
suitable.

It is hard to believe it is really either of those, as the error message
you give does not seem to be generated by the code snippet you give and
there is no reason to expect that it would be.
Dan anyone please tell me how to prints how a description of the error
from DBI when sql executed failed?

I'm not sure why you would expect an *execution* failure to occur in a
*prepare* method.

In my hands, I turn on RaiseError and it just works. No magic incantations
are necessary.

Given the almost complete absense of context you provide, it is hard to be
more helpful than that.

Xho
 
S

sam

It is not clear whether this is what you want but for some reason you
aren't getting it, or if this is what you get and it is for some reason not
suitable.

It is hard to believe it is really either of those, as the error message
you give does not seem to be generated by the code snippet you give and
there is no reason to expect that it would be.




I'm not sure why you would expect an *execution* failure to occur in a
*prepare* method.

In my hands, I turn on RaiseError and it just works. No magic incantations
are necessary.

Given the almost complete absense of context you provide, it is hard to be
more helpful than that.
Hi,
Do you have any example?
The following is a copy of the sample code that does not print out DBI
error:

#!/usr/bin/perl

use DBI;

# connect using to the database named $database using given
# username and password, return a database handle
$database = "mydb";
$username = "me";
$pw = "mypass";
$dbh = DBI->connect("DBI:mysql:$database",$username,$pw);
die "Unable to connect: $DBI::errstr\n" unless (defined $dbh);

$sth = $dbh->prepare(q{SELECT * from customer}) or die "Unable to prep
our query:".$dbh->errstr."\n";
$rc = $sth->execute or die "Unable to execute our query:".$dbh->errstr."\n";

while ($aref = $sth->fetchrow_arrayref){
for ($i=0; $i < $sth->{NUM_OF_FIELDS};$i++){
print $sth->{NAME}->[$i].": " . $aref->[$i] . "\n";
}
}

# tells server you will not need more data from statement handle
# (optional, since we're just about to disconnect)
$sth->finish;
# disconnects handle from database
$dbh->disconnect;

Thanks
sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top