NYCPHP Meetup

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

web dream works wdw wdwtest at gmail.com
Mon Aug 6 01:11:12 EDT 2007


Hi there,

you can try for $$phpvar in the query. It might work.
e.g

$sth = $this->conn->prepare ("SELECT * FROM table WHERE column LIKE
\"%$$phpvar%\"");


On 8/5/07, Jakob Buchgraber <jakob.buchgraber at googlemail.com> wrote:
>
> 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
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070805/19f76a02/attachment.html>


More information about the talk mailing list