Re: cgi ordering a table with sql

[email protected] (Gunnar Hjalmarsson)
Newsgroups perl.beginners
Message-ID <[email protected]>
Jenda Krynicky wrote:
> From: "Pat Rice" <[email protected]>
>> 
>> my $sth = $dbh->prepare('SELECT * FROM test1 ORDER BY ?');
> 
> Most databases would not let you prepare a statement like this. Most 
> often only values may be replaced by placeholders, not column names.

Hmm.. My fault, obviously. I had no idea.

So, what you are saying is that

     my $sth = $dbh->prepare('SELECT * FROM test1 ORDER BY ?');
     $sth->execute($sortby);

should better be replaced by

     my $sth = $dbh->prepare("SELECT * FROM test1 ORDER BY $sortby");
     $sth->execute();

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.