Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I most often use SQLite.
I use $dbh (data base handle) instead of $conn.

First of all, you have to connect to the Database using the DBI module.

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError = +> 1}) or die "Couldn't connect to database: " . DBI->errstr;
If $dbh is zero undefined, then the connect failed!
If the connection works, then I've given some guidance about how to handle future errors.
Your connect syntax will be different for the Oracle database.

Next step is to prepare your SQL statement:

my $get_all_user_rows = $dbh->prepare ("SELECT * FROM users");
I use all CAPS for SQL keywords, but that is just my preference - doesn't matter.

Now you have to execute the prepared SQL statement:

$get_all_user_rows->execute();
Now you have to retrieve the data from that executed statement.
The easiest in this case, would be to ask for a reference to all of the rows.

my $all_row_ref = $get_all_user_rows->fetchall_arrayref;
Now print the data from this 2-D array:
foreach my $row_ref (@$all_row_ref) { print "@$row_ref\n"; }
There is more, a lot more to this than the basics I showed above.
I may have made a mistake which the other Monks will quickly point out.
I don't have your DB, but this is, I think a general "roadmap" to get a first result.

In reply to Re: Perl Not returning SQL query result by Marshall
in thread Perl Not returning SQL query result by santoo

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found