Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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...


In reply to Re: Can't crack a DBI Error: by Daruma
in thread Can't crack a DBI Error: by Hammy

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2018-02-26 01:58 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (316 votes). Check out past polls.