Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: WordPress prepared statement with IN() condition #10032
    blankturgut-sariam
    Participant

    WordPress already has a function for this purpose, see esc_sql(). Here is the definition of this function:

    Escapes data for use in a MySQL query. Usually you should prepare queries using wpdb::prepare(). Sometimes, spot-escaping is required or useful. One example is preparing an array for use in an IN clause.

    You can use it like this:

    $villes = ["paris", "fes", "rabat"];
    $villes = array_map(function($v) {
        return "'" . esc_sql($v) . "'";
    }, $villes);
    $villes = implode(',', $villes);
    $query = "SELECT distinct telecopie FROM `comptage_fax` WHERE `ville` IN (" . $villes . ")"
    
Viewing 1 post (of 1 total)