PDO + ORDER BY with prepared statements!
- From: "João Morais" <jcsmorais@xxxxxxxxx>
- Date: Thu, 28 Feb 2008 04:06:39 -0800 (PST)
Hi there guys,
I've been working with PDO for a couple of days now.. and now I got
into this problem:
$order_by = 'field1';
$order_type = 'DESC';
$query = 'SELECT field1, field2, field3 ';
$query .= 'FROM table ';
$query .= 'ORDER BY :order_by :order_type ';
$stmt = $dbh->prepare($query);
$stmt->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$stmt->bindParam(':order_type', $order_type, PDO::PARAM_STR);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_NUM))
method_to_display($row);
When statement gets executed it returns true, although while I'm
listing query results they aren't sorted by field1 with specified
order_type.
Can any one explain what I'm doing wrong?
Thanks in advance.
.
- Follow-Ups:
- Re: PDO + ORDER BY with prepared statements!
- From: Rik Wasmus
- Re: PDO + ORDER BY with prepared statements!
- Prev by Date: Re: fopen - how to get a site with login
- Next by Date: Re: DOCTYPE
- Previous by thread: fopen - how to get a site with login
- Next by thread: Re: PDO + ORDER BY with prepared statements!
- Index(es):