PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #3841

Statement Prepare function too greedy

Details

Submitted2005-03-16 10:23 UTC
Fromsintemaa at hotmail dot com
Assigneddanielc
StatusBogus
PackageDB
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-03-16 10:23 UTC] sintemaa at hotmail dot com

Description:
------------
The Statement preparation function in DB tries to find all wildcards so they can be replaced during execution.

For this is recognizes all instances of ?, ! and & as wildcards.

However in MySQL != is used as unequal operator. Prepare recognizes the ! as a wildcard, takes it out, and on execution it crieds a mismatch as you don't supply enough parameters for the foudn wildcards.

Reproduce code:
---------------
$sql = 'SELECT * FROM mytable WHERE id < ? AND id != 10';
$sth = $db->prepare($sql);
$result = $db->execute($sth, 100);

Expected result:
----------------
$result should contain all rows from mytable where the id is smaller than 100 and not equal to 10

Actual result:
--------------
A DB_Error is returned

Standard Message: DB Error: mismatch
Standard Code: -7

DBMS/User Message: SELECT * FROM mytable WHERE id < AND id = 10 [DB Error: mismatch]