note 61505 modified in pdostatement.bindparam by danbrown

From: Date: Tue, 17 May 2011 18:12:12 +0000
Subject: note 61505 modified in pdostatement.bindparam by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179834@lists.php.net to get a copy of this message
A caution for those using bindParam() on a placeholder in a LIKE '%...%' clause, the following code will likely not work: <?php $q = "SELECT id, name FROM test WHERE name like '%:foo%'"; $s = "carrot"; $sth = $dbh->prepare($q); $sth->bindParam(':foo', $s); $sth->execute(); ?> What is needed is something like the following: <?php $s = "%$s%"; $sth->bindParam(':foo', $s); ?> This should work. Tested against mysql 4.1, PHP 5.1.3. --was-- A caution for those using bindParam() on a placeholder in a LIKE '%...%' clause, the following code will likely not work: $q = "SELECT id, name FROM test WHERE name like '%:foo%'"; $s = "carrot"; $sth = $dbh->prepare($q); $sth->bindParam(':foo', $s); $sth->execute(); What is needed is something like the following: $s = "%$s%"; $sth->bindParam(':foo', $s); This should work. Tested against mysql 4.1, PHP 5.1.3. http://php.net/manual/en/pdostatement.bindparam.php

« previous php.notes (#179834) next »