pdo LIKE子句和IN子句

时间:2017-06-24 16:29:44

标签: mysql pdo

$sql = "SELECT id, trader_currency FROM active_trades WHERE status=? AND open_time IN (LIKE ?, LIKE ?, LIKE ?)";

$q = $conn->prepare($sql);

$result = $q->execute(array("Closed", "%".$todayDate."%", "%".$yesterdayDate."%", "%".$last2dayDate."%"));

如何在pdo中组合like子句和in子句?上面的代码有语法错误。

1 个答案:

答案 0 :(得分:1)

只需OR条件:

$sql = 'SELECT id, trader_currency, open_time 
        FROM active_trades 
        WHERE status=?
            AND (
                open_time LIKE ? 
                OR open_time LIKE ? 
                OR open_time LIKE ?
           )';