Possible Duplicate:
PHP Prepared Statements… Bind variable as numeric range in REGEXP?
$query = "SELECT * FROM `mytable` WHERE `file` REGEXP 'This string :var'";
$stmt = $dbh->prepare($query);
$stmt->bindValue(':var', 'exists');
$stmt->execute();
This throws error:
SQLSTATE[42000]: Syntax error or access violation
When I echo $query before the execute, I get:
SELECT * FROM `mytable` WHERE `file` REGEXP 'This string :var'
How the hell do you bind variables in a regexp?
Two things: You need to tell mysql what column you wish to apply
REGEXPto and a placeholders can only be used where a value can appear (thanks to @Barmar). For example, if you wish to searchcol1for'This string :var'you need to do