From: jake_lake at selinc dot com Operating system: Ubuntu 8.10 PHP version: 5.2.9 PHP Bug Type: PostgreSQL related Bug description: pg_query_params doesn't accepted ORDER BY parameter
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 hholz...@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 hholz...@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 -- Edit bug report at http://bugs.php.net/?id=48588&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48588&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48588&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48588&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48588&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48588&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48588&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48588&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48588&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48588&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48588&r=support Expected behavior: http://bugs.php.net/fix.php?id=48588&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48588&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48588&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48588&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48588&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48588&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48588&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48588&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48588&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48588&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48588&r=mysqlcfg