ID:               36281
 Updated by:       [EMAIL PROTECTED]
-Summary:          bindParam not working with LIKE '%:foo%'
 Reported By:      vendor at visv dot net
-Status:           Analyzed
+Status:           Bogus
 Bug Type:         Documentation problem
 Operating System: Linux
 PHP Version:      5.1.2
 New Comment:

The bug reporter has erred in assuming that parameters can be replaced
_inside_ delimited strings within the SQL statement; he or she is
treating parameter markers like plain old PHP variables. Of course,
that would lead directly to possible SQL injection, which is exactly
what bound parameters are meant to avoid.

(Also, the sample code provided is missing an ending double-quote on
the first line.)

I'm sure the application will work as intended if rewritten as
follows:

$q = "SELECT id, name FROM test WHERE name like :foo";
$s = "carrot";

$dbh = new PDO('mysql:...', $user, $pass);

$sth = $dbh->prepare($q);
/* prepend and append % around the user-supplied value to match
anywhere in the NAME field */
$s = "%{$s}%";
$sth->bindParam(':foo', $s);
$sth->execute()

while ($r = $sth->fetch()) {
    print_r($r);
}



Previous Comments:
------------------------------------------------------------------------

[2006-02-04 18:54:21] vendor at visv dot net

Possibly. How can we determine that definitively? At the
least, I would like to add a user-note to the online
documentation, if someone cannot add it to the core docs
for pdo-mysql.

The db in question is mysql 4.1

------------------------------------------------------------------------

[2006-02-04 18:49:21] [EMAIL PROTECTED]

I doubt this is a bug... many DB APIs simply don't support bind
variables like this. A bind variable is not just any substitution for a
string.

------------------------------------------------------------------------

[2006-02-04 18:49:15] [EMAIL PROTECTED]

That is not a valid parameter definition.


------------------------------------------------------------------------

[2006-02-04 18:21:16] vendor at visv dot net

No change nor improvement with
http://snaps.php.net/php5.1-latest.tar.gz on Feb 4. 12:20PM

------------------------------------------------------------------------

[2006-02-04 12:48:08] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip



------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/36281

-- 
Edit this bug report at http://bugs.php.net/?id=36281&edit=1

Reply via email to