Skip to content

Bug: mysqli_sql_exception when using ->withIdentities() #512

Closed
@virdb

Description

@virdb

PHP Version

7.4.32 | 8.1.12

CodeIgniter4 Version

4.2.10

Shield Version

dev-develop dd18be0

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli-server (PHP built-in webserver)

Database

MariaDB 10.9.3

Did you customize Shield?

No

What happened?

Consider this code in controller:

$userModel = new UserModel();
$users = $userModel->like('username','')
                            ->withIdentities()
                            ->findAll();

This works returning all not deleted usernames.
If I try to search a specific, existing user ("admin"), it also works finding the user:

$userModel = new UserModel();
$users = $userModel->like('username','adm')
                            ->withIdentities()
                            ->findAll();

Now, if I try the same search, but with a match that doesn't match any user, like:

$userModel = new UserModel();
$users = $userModel->like('username','foo')
                            ->withIdentities()
                            ->findAll();

It generate an error:

mysqli_sql_exception #1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')
ORDER BY `id`' at line 3
SYSTEMPATH/Database/MySQLi/Connection.php at line 292

If I remove ->withIdentities(), it return an empty array

Steps to Reproduce

see previous description

Expected Output

empty array

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions