No Code Attached Yet
avatar sergeytolkachyov
sergeytolkachyov
9 Jul 2025

Steps to reproduce the issue

Database driver: mysqli.
First lets sure that all is ok with with other tables. Try to execute this queries:

use Joomla\CMS\Factory;

$app   = Factory::getApplication();
$db = Factory::getContainer()->get('DatabaseDriver');
// Get query 1
$query = $db->getQuery(true);
// Select some articles with id 5, 8 and 10. Specify this your articles ids.
$query->select('*')->from('#__content')->whereIn('id', [5,8,10]);
$result1 = $db->setQuery($query)->loadAssocList();
// check the result - articles list
// We got an array with 3 articles. ok.
dump($query, $result1);

// Do the same for another articles list
$query = $db->getQuery()->clear();
// or
$query = $db->getQuery(true);
// or
$query->clear(); // We try to save memory and use existing $db
// Fetch 2 another articles
$query->select('*')->from('#__content')->whereIn('id', [1,2]);
$result2 = $db->setQuery($query)->loadAssocList();
// All is fine. We got an array with 2 articles
dump($query, $result2);

You can check some other tables. I tried with #__action_logs - that works fine.
Try to do the same with #__users table. I have a 2 users on test stand.

// Get query 1
$query = $db->getQuery(true);
// Select one user with email.
$query->select('*')->from('#__users')->whereIn('email', [$db->quote('info@web-tolk.ru')]);
$result1 = $db->setQuery($query)->loadAssocList();
// check the result - I expect a list consist of only 1 user with specified email
// But I got a 2 users
dump($query, $result1);

$query = $db->getQuery()->clear();
// or
$query = $db->getQuery(true);
// or
$query->clear(); // We try to save memory and use existing $db
// Try to fetch second user data
$query->select('*')->from('#__users')->whereIn('username', ['test']);
$result2 = $db->setQuery($query)->loadAssocList();
// I got a 2 users list, but only 1 user expected.
dump($query, $result2);

Demo video 1

09-07-2025.175750.mp4

If you change your SQL queries types from Query class to simple string query - all is fine.
Try this queries (with your local users data):

$query = "SELECT * FROM #__users WHERE email IN(".$db->quote('info@web-tolk.ru').")";

will return a list with 1 user.

$query = "SELECT * FROM #__users WHERE username IN(".$db->quote('test').")";

will return a list with 1 user.

Demo video 2.

09-07-2025.180516.mp4

How I found this issue?

I writing a user import plugin from CRM. I try to find an existing user by email and if there is no duplicates - I'll create a new user. If email is exists - I'll link his CRM profile to Joomla user. But there are 2 or more emails for each contact can be specified in CRM, then I must to check all of them. So, I took a whereIn() method and got a wrong results from database. Email wich I checked was not found in Joomla database, but sql query returns to me prevouse sql query result for this table.

I found that the rowBindedValues property in second query has an old values from previous query.

09-07-2025.182031.mp4

Expected result

Expect that the whereIn() works perfect for #__users table

Actual result

SQL query returns wrong data from #__users table

System information (as much as possible)

Joomla 5.3.2

Additional comments

I may have identified the cause incorrectly. I came across this behavior specifically with the #__users table on two different Joomla installations.

avatar sergeytolkachyov sergeytolkachyov - open - 9 Jul 2025
avatar joomla-cms-bot joomla-cms-bot - change - 9 Jul 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Jul 2025
avatar sergeytolkachyov sergeytolkachyov - change - 9 Jul 2025
The description was changed
avatar sergeytolkachyov sergeytolkachyov - edited - 9 Jul 2025
avatar sergeytolkachyov sergeytolkachyov - change - 9 Jul 2025
The description was changed
avatar sergeytolkachyov sergeytolkachyov - edited - 9 Jul 2025
avatar heelc29
heelc29 - comment - 10 Jul 2025

whereIn uses by default INT to bind the values
https://github.com/joomla-framework/database/blob/ff7ee9693fdbd0c041fb6328e457f062aab15ffc/src/DatabaseQuery.php#L1793

If you use stings you have to add the third parameter with \Joomla\Database\ParameterType::STRING

avatar sergeytolkachyov sergeytolkachyov - change - 10 Jul 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-07-10 05:04:00
Closed_By sergeytolkachyov
avatar sergeytolkachyov sergeytolkachyov - close - 10 Jul 2025
avatar sergeytolkachyov
sergeytolkachyov - comment - 10 Jul 2025

@heelc29 thank you. That solved my issue.

Add a Comment

Login with GitHub to post a comment