PHP可以在SQL预处理语句中绑定数字列表吗?

I am converting a Coldfusion website to PHP. I have a query that looks in a list of comma separated numbers to see if there is a match and then responds accordingly. This is the where statement I am currently using.

WHERE (`link_issue_category`.`Category_ID` IN (<CFQUERYPARAM value="#Category_id#" list = "yes">)

How do I write this in PHP?

CFQUERYPARAM does some validation on the value, and if possible sets up a bind parameter. You can probably just embed the value into the SQL, assuming you've already done validation / sanitization on it. The list parameter specifies that this is a comma-delimited list. You should be able to plug this list directly into the query, depending on the value type.

"WHERE (`link_issue_category`.`Category_ID` IN ($category_id)";

If your values in the list are strings, you may need to wrap them in qoutes before they go into the query.

FYI CF just creates a new prepared statement with the number of ? being the same as the length of your list behind the scene.

So if you want the same behaviour in PHP, it wouldn't be that hard really. Just dynamically create a new prepared statement, and bind them accordingly.

PHP Prepared statements: http://php.net/manual/en/pdo.prepared-statements.php

However, you could have just use regex to validate the list of values to numeric value and comma's only, and use the variable as part of the SQL statement.