How do I use pdo's prepared statement for order by and limit clauses(or can I?If not,what should I r

Posted by user198729 on Stack Overflow See other posts from Stack Overflow or by user198729
Published on 2010-04-21T14:04:31Z Indexed on 2010/04/21 15:23 UTC
Read the original article Hit count: 198

Filed under:
|
|
$sql = "SELECT * FROM table ORDER BY :sort :dir LIMIT :start, :results";
$stmt = $dbh->prepare($sql);
$stmt->execute(array(
     'sort'  => $_GET['sort'], 
     'dir'  => $_GET['dir'], 
     'start'  => $_GET['start'],
     'results' => $_GET['results'],
     )
    );

I tried to use prepare to do the job,but $stmt->fetchAll(PDO::FETCH_ASSOC); returns nothing.

Can someone point out what's the wrong thing I am doing?

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo