Proper WordPress Prepared Statement with IN() Condition for Multiple Values
When using prepared statements in WordPress, handling multiple values within an IN() condition can pose a challenge. This issue arises when the input values, stored in strings with double quotes, are not parsed correctly, resulting in a single string with escaped quotes.
To implement a prepared statement correctly in WordPress for multiple values, use the following approach:
Consider the following example:
// Values for IN() condition $villes = array('paris', 'fes', 'rabat'); // Generate SQL statement $sql = "SELECT DISTINCT telecopie FROM `comptage_fax` WHERE `ville` IN(" . implode(', ', array_fill(0, count($villes), '%s')) . ")"; // Prepare query $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $villes)); echo $query;
This code will output the correct SQL statement with three separate values in the IN() condition. Using this technique, you can ensure that prepared statements work as intended with multiple values in WordPress.
以上是如何在 WordPress 中使用帶有 IN() 條件的準備語句來取得多個值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!