Re: PDO bindValue ORDER BY

From: Date: Fri, 31 Oct 2008 23:46:59 +0000
Subject: Re: PDO bindValue ORDER BY
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-45579@lists.php.net to get a copy of this message
Technically, bound parameter is expecting a value, such as WHERE ID=:id However, ORDER BY is followed by a field name, such as ORRDER BY ID So I don't think it should work. If it does work, then it is a sign that the database driver is not really preparing the statement (as it should for performance reason), but it is just substituiting values to compose a SQL (just for your convenience). On 10/31/08, Matthew Peltzer <goochrules@gmail.com> wrote: > Are pdo bound parameters within an ORDER BY clause broken in php 5.2.5? > > I find that in php 5.2.6 this works as expected: > > <?php > $sql = 'SELECT * FROM table ORDER BY :sort'; > $stmt = $pdo->prepare($sql); > $stmt->bindValue(':sort', $sort, PDO::PARAM_STR); > $stmt->execute(); > print_r($stmt->fetchAll(PDO::FETCH_ASSOC)); > ?> > > but under php5.2.5 the ORDER BY clause silently fails. Also, > parameters bound to SELECT or WHERE or LIMIT clauses function > correctly, but ORDE BY still has no effect. If I remove the > "$stmt->bindValue(':sort', $sort, PDO::PARAM_STR);" line or the > "ORDER > BY :sort" I get a "number of bound variables does not match number of > tokens" error. > > So it appears the parsing mechanism is funcitoning, but what ever is > responsible for binding to ORDER BY is not. > > I've looked in bug reports and the change logs, but did not find a > explicit reference to this issue. > > > -- > -- Matthew Peltzer > -- gooch@goochrules.net > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.db (#45579) next »