kiat has asked for the wisdom of the Perl Monks concerning the following question:
What is the normal way to execute multiple sql queries? Suppose I've an sql query to describe a table and a second one to select all the elements of a table, how do I execute both queries and print out the data?
Here is how I do it:
Is that how it's normally done?# Store sql queries in @sqls push (@sqls, qq{ DESCRIBE $table{'profile'} }); push (@sqls, qq{ SELECT * FROM $table{'profile'} }); html_start(); print qq~<table>\n~; foreach (@sqls) { $sth = $dbh->prepare($_); $sth->execute() or bail_out("Cannot execute query."); while (my @ary = $sth->fetchrow_array()) { print qq~<tr valign="top">\n~; foreach (@ary) { print qq~<td>$_</td>\n~ if $_; } print qq~</tr>\n~; } } print qq~</table>\n~; html_end();
Thanks in anticipation :)
20031204 Edit by Corion: Changed title from 'multiple perl-myslq queries...'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple perl-mysql queries...
by jeffa (Bishop) on Dec 04, 2003 at 14:30 UTC | |
by kiat (Vicar) on Dec 04, 2003 at 14:47 UTC | |
by jeffa (Bishop) on Dec 04, 2003 at 14:54 UTC | |
by kiat (Vicar) on Dec 04, 2003 at 15:52 UTC | |
by jeffa (Bishop) on Dec 04, 2003 at 18:30 UTC | |
|
Re: multiple perl-mysql queries...
by hardburn (Abbot) on Dec 04, 2003 at 14:38 UTC | |
|
Re: multiple perl-mysql queries...
by Abigail-II (Bishop) on Dec 04, 2003 at 14:32 UTC |