in reply to Perl Not returning SQL query result
I most often use SQLite.
I use $dbh (data base handle) instead of $conn.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.
The easiest in this case, would be to ask for a reference to all of the rows.
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.
I use $dbh (data base handle) instead of $conn.
First of all, you have to connect to the Database using the DBI module.
If $dbh ismy $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError = +> 1}) or die "Couldn't connect to database: " . DBI->errstr;
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:
I use all CAPS for SQL keywords, but that is just my preference - doesn't matter.my $get_all_user_rows = $dbh->prepare ("SELECT * FROM users");
Now you have to execute the prepared SQL statement:
Now you have to retrieve the data from that executed statement.$get_all_user_rows->execute();
The easiest in this case, would be to ask for a reference to all of the rows.
Now print the data from this 2-D array:my $all_row_ref = $get_all_user_rows->fetchall_arrayref;
There is more, a lot more to this than the basics I showed above.foreach my $row_ref (@$all_row_ref) { print "@$row_ref\n"; }
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl Not returning SQL query result
by afoken (Chancellor) on May 12, 2021 at 20:33 UTC | |
by Marshall (Canon) on May 12, 2021 at 22:09 UTC | |
by afoken (Chancellor) on May 13, 2021 at 22:06 UTC | |
by pryrt (Abbot) on May 13, 2021 at 23:06 UTC | |
by Marshall (Canon) on May 15, 2021 at 02:31 UTC |
In Section
Seekers of Perl Wisdom