Mysql like

I have the following model

    function offline_orders($term)
    {
        $sql    =     "SELECT  O.order_date
                           , C.name
                        FROM offline_orders O
                        JOIN customers C ON O.customerid = C.customer_id
                       WHERE C.name LIKE :term";
                       
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute(array(':term' => '%'.$term.'%'));
        
        return $stmt->fetchAll();
        
    }

How do i make the LIKE statement case insensitive

You can try and use a case insensitive collation on your query, like COLLATE UTF8_GENERAL_CI.

Try

$sql    =     "SELECT  O.order_date
                       , C.name
                    FROM offline_orders O
                    JOIN customers C ON O.customerid = C.customer_id
                   WHERE C.name LIKE :term COLLATE utf8_general_ci";

This should do the trick.

That works great. Thanks a lot :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.