Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #17890 Improper use of array_search in psgsql.php v1.173 prepare function
Submitted: 2010-09-24 00:20 UTC
From: fletcherj Assigned: quipo
Status: Closed Package: MDB2 (version 2.4.1)
PHP Version: 5.3.1 OS: Windows XP
Roadmaps: 2.5.0b4    

 [2010-09-24 00:20 UTC] fletcherj (Fletcher Johnston)
Description: ------------ When more than one parameter appears in a query, they are not replaced with a proper placeholder because the php array_search function is used improperly in the pgsql driver prepare function. See php documentation under "Return Values": This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Use the === operator for testing the return value of this function. No explicit comparison to FALSE is made, so the IF statement is not entered when the index returned is 0. This results in the same parameter appear in the $positions array multiple times. Also, though this is not related to the bug, it appears that the $next_parameter variable is never actually read from. And the FOREACH loop within the IF statement doesn't appear to do anything either. I have attached a txt file which contains lines 880 through 897 from pgsql.php which contains a fix. Test script: --------------- $sql = "select * from table1 as T1 LEFT JOIN table1 as T2 on = :id1 LEFT JOIN table1 as T3 on = :id2 WHERE :id1 IS NOT NULL AND :id2 IS NOT NULL"; $vals = array('id1'=>1, 'id2'=>2); $stmt = $acl->db->prepare( $sql ); $result = $stmt->execute($vals); Expected result: ---------------- ["positions"]=> array(2) { [0]=> string(3) "id1" [1]=> string(3) "id2" } Actual result: -------------- ["positions"]=> array(2) { [0]=> string(3) "id1" [1]=> string(3) "id2" [2]=> string(3) "id1" }


 [2010-09-24 00:23 UTC] fletcherj (Fletcher Johnston)
 [2010-09-25 15:50 UTC] quipo (Lorenzo Alberton)
-Status: Open +Status: Closed -Assigned To: +Assigned To: quipo
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.