views:

51

answers:

1

Let's say I have 2 pdo statements that differ only in order (asc vs. desc)

$stmt1 = $po->prepare("SELECT * FROM tabname WHERE categ=:categ ORDER BY field1 DESC");
$stmt2 = $po->prepare("SELECT * FROM tabname WHERE categ=:categ ORDER BY field1 ASC");

Is there a way I can bind ASC/DESC dynamically so I can have only 1 stmt

$order = "ASC"; //or "DESC"

$stmt = $po->prepare("SELECT * FROM tabname WHERE categ=:categ ORDER BY field1 order=:order");
$stmt->bindParam(':order', $order, PDO::PARAM_STR);
+2  A: 

no. parameters are automatically quoted, and ASC/DESC shouldn't be quoted. this is the same reason that table and column names can't be parameters.

longneck