Mysql reading via Perl DBI
I use the DBI module and I wander if my way to retrieve data from tables is good.
There are a few rows in the table, I scan them all and build an array from each of it: Code:
my $sth = $dbh->prepare ("SELECT date FROM msgs"); |
As usual, TIMTOWTDI, but this would work:
Code:
$sth = $dbh->prepare ("SELECT date, nick, msg FROM msgs"); The "while()" line could be while( @p_info = $sth->fetchrow() ) for the same SQL as I've used.... and do some thing different with the hash assignment line... :) HTH |
preparing a query is a relatively expensive operation.
if you have single table .. select * from the table fetch all data inside a hash or array and use it where ever required.. no need to prepare saperately for each column date nick and msg. |
All times are GMT -5. The time now is 11:58 AM. |