NYCPHP Meetup

NYPHP.org

[nycphp-talk] PDO and Prepared Statements in MySQL when using LIKE [expr]

Jakob Buchgraber jakob.buchgraber at googlemail.com
Sun Aug 5 13:48:31 EDT 2007


hey!

I have some query with a LIKE expression e.g. "SELECT * FROM table WHERE 
column LIKE "$phpvar%", but I would like to use prepared statements 
instead of writing the variable directly into the query. So I write:

$sth = $this->conn->prepare ("SELECT * FROM table WHERE column LIKE 
\":phpvar%\"");
$sth->bindParam (":phpvar", $phpvar);
$sth->execute();
var_dump ($sth->fetchAll());

Here I get an empty result set when using prepared statements. However 
when just using string concatenation and putting the variable directly 
into the query it works fine.

Is this expected or a bug?

Cheers,
Jakob

-- 
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0



More information about the talk mailing list