in reply to Perl Not returning SQL query result
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;
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();
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"; }
|
|---|
| 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 |