Re: PDO bindValue ORDER BY

From: Date: Sun, 02 Nov 2008 22:38:16 +0000
Subject: Re: PDO bindValue ORDER BY
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-45585@lists.php.net to get a copy of this message
Matthew Peltzer wrote:
ok... this makes more sense now. I know in the past I tried to do something similar with table names in the WHERE clause, and that didn't work in the same manner. Is there a better way to do what I'm trying to do? that is, sorting within the SQL statement based on a supplied column name without out writing multiple SQL statements? for now my work around is to some thing like: $sort = mysql_real_escape_string($sort); $sql = "SELECT * FROM table ORDER BY $sort"; which makes me queasy because I spent a lot of time getting away from inlining variables in SQL statements.
Validate your data. You're just making a bad query here. I somehow get "orderby" to be "field_that_does_not_exist". You end up with: select * from table where blah order by field_that_does_not_exist; which will generate a mysql_error and give no results at all. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#45585) next »