From:             atrauzzi at gmail dot com
Operating system: Ubuntu
PHP version:      5.2.5
PHP Bug Type:     PDO related
Bug description:  Binding to unset placeholders.

Description:
------------
PHP doesn't support automatic-skipping of placeholders that aren't in a
prepared statement.

It would be nice if this rather simple scenario could be handled as it's
forcing me to double up on my checks when generating a query.

It's hard to determine whether this is truly an error condition or not.  I
hope the issue doesn't bounce without due consideration.

My suggestion is to have the Statement object ignore requests to bind to
fields not present in the query.  It might be sloppy, so to that end, I'm
happy to see any suggestions for alternatives.

Hopefully I'm not missing a best practice here either ;)

Reproduce code:
---------------
The generalized steps are:

o Go through steps to generate query.  At some point during this, the
string being built has placeholders (Example: ":userID" and ":isActive")
that need to be added.  More often that not these will be surrounded by
conditions like "if($lookingForUser)".
o Take the completed query string and generate a prepared statement.
o Bind all requested parameters.

The problem here is at the "Bind all requested parameters" step.  It is
there that we'll see an almost identical set of condition checking as
encountered during the "Go through steps to generate query" phase.
If I don't want ":isActive" in my query, I have to not only dodge it when
generating my query, but also when binding parameters with an identical set
of checks.

There must be a cleaner way to do this?!

Expected result:
----------------
bindParam should not throw any errors when the parameter isn't present in
the query.

Actual result:
--------------
bindParam throws an error when you try to bind a parameter that isn't
present in the query.

-- 
Edit bug report at http://bugs.php.net/?id=44832&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44832&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44832&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44832&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44832&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44832&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44832&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44832&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44832&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44832&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44832&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44832&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44832&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44832&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44832&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44832&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44832&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44832&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44832&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44832&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44832&r=mysqlcfg

Reply via email to