Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Can't crack a DBI Error:

by Daruma (Curate)
on Sep 24, 2002 at 14:50 UTC ( #200385=note: print w/replies, xml ) Need Help??

in reply to Can't crack a DBI Error:


I tested the following (using DBD::Oracle, mind you)

use strict; use DBI; use diagnostics; my $user = 'foo'; my $pass = 'bar'; my $dbh= DBI->connect( "dbi:Oracle:database", "$user", "$pass", ) or die "Can't connect to the database: $DBI::errstr\n"; my $sql = ' Select employee_id, employee_last_name, employee_grade from employees'; my $sth = $dbh->prepare($sql) or die "Can't prepare SQL statement: $DBI::errstr\n"; unless ($sth->execute) { fatal ("SQL query failed: " . $sth->errstr . "\n$sql"); } my $ref = $sth->fetchrow_arrayref() or die "Can't fetch: $DBI::errstr\n"; $sth->finish; print "@$ref[0] - @$ref[1] - @$ref[2]\n"; $dbh->disconnect;
If I remove the $sth->finish; line, It returns an error when attempting to disconnect against an open database handle... the fetch is still fetching... With the finish method, I do return just one row. Does that meet your need?

Beyond the fetchrow_array / finish vs. selectrow_array difference pointed out by Abstraction++, The code works fine for me.

Are you using strict, warning & diagnostics?? Is your code giving you feedback for every DBI package usage? (Have it die and give you feedback...


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://200385]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2022-08-16 09:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found