On Tue, Jan 30, 2001 at 09:52:33AM -0600, Steve Berlage wrote:
> Is it possible to use placeholders in an order by clause?  The code
> below executes fine but is not sorted correctly.
> 
> $sth = $dbh->prepare("SELECT projectnumber, companyname, engineer
>                                                  FROM project
>                                                 WHERE projectmanager =
> '$fullname' AND projectclass = 'Active'
>                                                 ORDER BY ?");
> 
> $sth->execute(projectnumber);

The SQL you are executing is:

  SELECT projectnumber, companyname, engineer
  FROM project
  WHERE projectmanager = '$fullname' AND projectclass = 'Active'
  ORDER BY 'projectnumber'

'projectnumber' is a constant string, so the order by clause is
ineffective.

Placeholders may only be used in place of data values, not in place of
table names, column names, SQL keywords, or other such things.

Ronald

Reply via email to