Welcome Guest, Not a member yet? Register   Sign In
Problem with Query Builder Not Returning Results for a LIKE Query
#1

(This post was last modified: 08-14-2024, 03:52 AM by modismos.)

Hi everyone,

I've recently started working with CodeIgniter 4, and I'm encountering an issue with the Query Builder when using the LIKE clause. I'm trying to filter records from my database based on a search term, but it seems like the query isn't returning any results, even though I know matching records exist.

Here's a simplified version of my code:

Code:
$searchTerm = 'example';
$builder = $db->table('my_table');
$query = $builder->like('column_name', $searchTerm)->get();
$results = $query->getResult();

if (empty($results)) {
    echo "No records found";
} else {
    foreach ($results as $row) {
        echo $row->column_name;
    }
}

I've checked my database, and there are definitely rows where column_name contains the word 'example'. I've tried tweaking the query, but no luck so far. Could it be something related to how CodeIgniter 4 handles the like clause or perhaps an issue with the character encoding?

Any insights or suggestions on what I might be doing wrong would be greatly appreciated.
Thanks and Regards,
Elena Idioms
Reply
#2

Check the real SQL statement that are executed by Debug Toolbar.
Reply
#3

(08-05-2024, 08:06 PM)modismos Wrote: Could it be something related to how CodeIgniter 4 handles the like clause or perhaps an issue with the character encoding?

If you use an incorrect character encoding, yes, you would have issues.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB