in reply to DBI, From PHP to Perl
Note that with DBI, it's better to use placeholders (instead of putting variables in your sql) because DBI will then take care of any quoting issues for you.## chunk 'O' code @sql = ( "SELECT COUNT(*)", "FROM sc_products WHERE name LIKE ? AND keywords LIKE ?" ); @args = ("%$search_name%", '%Color%'); $sth = $dbh->prepare(join ' ', @sql); $sth->execute(@args) || $error->LogError("Error opening database connection f +or product count in search.cgi".$dbh->errstr, 0); # get my count my ($count) = $sth->fetchrow_array; $sth->finish; $sql[0] = "SELECT name, image2"; $sth = $dbh->prepare(join ' ', @sql); $sth->execute(@args) || $error->LogError("Error opening database conne +ction f +or product count in search.cgi".$dbh->errstr, 0); while(my @results = $sth->fetchrow_array) { ## Use my count in here for some cool table formatting... print "<tr><td class=\"imgs\">... } $sth->finish; $dbh->disconnect();
|
|---|