0
votes
print_r($sql);
echo "\n";
print_r($sql_params);
$result = db_query($sql, $sql_params); // Error happening here

Output:

select SQL_CALC_FOUND_ROWS *  from rocdocs_database_1318520218 where 1=1  order by ? ? limit ?, ?
Array
(
    [0] => c5
    [1] => desc
    [2] => 0
    [3] => 50
)

According to the documentation I can used ordered parameters by using an array and ? marks, but it seems to be erroring. Any ways to debug this? I have installed devel, but it doesn't show the query.

1

1 Answers

0
votes

You can't use placeholders for anything that is "sql structure" like sort definitions, table/column names and so on. This is impossible.

If you need dynamic order by definitions, use db_select() and then orderBy(). Make sure to validate what you pass in through that.