PHP mysql REGEXP Prepared Statement

2019-08-08 08:08发布

问题:

I am very new to MYSQL and Prepared Statements. I have a few queries that I need to change to prepared statements. The problem is with this REGEXP query:

$objects = mysql_query("SELECT * FROM $table WHERE parent REGEXP ',". 
    $item .",|^". $item .",|,". $item ."\$|^". 
    $item ."\$'") or die(mysql_error());

How do you go about converting that to a prepared statement with place holders?

回答1:

You should make use of the CONCAT function inside the prepared statement query instead of using the classic . concatenation sign for regular queries. This should do the trick :)