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
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.
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.
Expect that the whereIn()
works perfect for #__users
table
SQL query returns wrong data from #__users
table
Joomla 5.3.2
I may have identified the cause incorrectly. I came across this behavior specifically with the #__users
table on two different Joomla installations.
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-07-10 05:04:00 |
Closed_By | ⇒ | sergeytolkachyov |
whereIn
uses by default INT to bind the valueshttps://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