|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-06-24 17:50 UTC] sjoerd-php at linuxonly dot nl
[2011-01-01 23:24 UTC] jani@php.net
-Summary: pg_query_params doesn't accepted ORDER BY parameter
+Summary: pg_query_params doesn't accept ORDER BY parameter
-Package: Feature/Change Request
+Package: PostgreSQL related
[2012-03-29 10:30 UTC] yohgaki@php.net
-Status: Open
+Status: Wont fix
[2012-03-29 10:30 UTC] yohgaki@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 12:00:02 2025 UTC |
Description: ------------ In attempting to use the pg_query_params function, it came to my attention that trying to use an ORDER BY with a parameter fails. After searching high and low I finally found someone else with the same issue. It was reported in Bug # 45101 and I believe falsely written-off as bogus. In the bug report Alan writes, " I've looked at the pg_trace() output and it appears to be doing the right thing. All I can assume is that the parameter is being converted to a TRUE for an ORDER BY, and so the database happily accepts 'ORDER BY 1'." This makes sense as then the query should run fine using the 1 as the column number and selecting the first column number from the table to order on. However, the given response by hholzgra@php.net does not make any sense. If the expression were to truly be evaluated using a constant string, PGSQL would return an error as strings cannot be in the ORDER BY clause, only column headers and integers representing the column # wanted to order on. Therefore, it seems as Alan was more on the right track assuming that for some reason the input value is being converted to TRUE or 1. This must surely be faulty behaviour as it essentially is ignoring any parameter assigned to ORDER BY and throwing out that part of the clause all together. If, however, this is the designed behaviour of this function, it should at least be documented so that others do not get caught up debugging for hours over this silly thing! Reproduce code: --------------- #!/opt/php/bin/php <?php /* create table php_bug (id integer, name varchar(255)); insert into php_bug values (1, 'one'); insert into php_bug values (2, 'two'); insert into php_bug values (3, 'three'); insert into php_bug values (4, 'four'); insert into php_bug values (5, 'five'); */ $conn = pg_connect('host=localhost dbname=test port=5432 user=web'); $sql = 'SELECT * FROM php_bug WHERE name LIKE $1 ORDER BY $2'; $params = array('%o%', 'doesnt_exist_and_should_be_an_sql_error'); if (! pg_connection_busy($conn)) pg_send_query_params($conn, $sql, $params); $res = pg_get_result($conn); while($row = pg_fetch_assoc($res)) echo "{$row['id']} - {$row['name']}\n"; ?> Expected result: ---------------- If passing as constant string like hholzgra@php.net claims: ERROR: non-integer constant in ORDER BY If passing as column header that doesn't exist: ERROR: column "doesnt_exist_and_should_be_an_sql_error" does not exist LINE 11: ORDER BY doesnt_exist_and_should_be_an_sql_error; ^ Actual result: -------------- 1 - one 2 - two 4 - four