-
-
Notifications
You must be signed in to change notification settings - Fork 38
Description
I am working to upgrade a module from Joomla 3 to Joomla 5. I'm using Joomla 5.0.2, PHP 8.2 and the module I'm upgrading has multiple dropdowns. I'm running into an error that I have not seen before and I'm stuck. This is the error:
2014 - Commands out of sync; you can't run this command now
I've built modules like this in Joomla 3 many times. The process is I'm calling a Stored Procedure to get the dataset I need to create the dropdown object, I return the created object and I move to the next dropdown. The functions are called sequentially from the main php file in the module to the helper.php file.
When I run the code this the first dropdown object is returned correctly. However, when the code reaches the setQuery line in the dropdown_2 function in the helper.php file I get the "out of sync" error listed above.
I thought the issue was with the dropdwon_2 function, but when I comment out the call to dropdown_1 function I receive back the dropdown_2 object and the error occurs in the dropdown_3 function, same place in the setQuery line. Any combination of running the different functions seems to produce the same result.
Steps to reproduce the issue
Here's an example of the code in my helper.php file.
public static function GetDropdown1($name, $details)
{
$db = Factory::getContainer()->get('DatabaseDriver');
$db->setQuery("call StoredProcedure_1");
$results1 = $db->loadObjectList();
...foreach to create the $dropdown_1 object
return $dropdown_1;
}
public static function GetDropdown2($name, $details)
{
$db = Factory::getContainer()->get('DatabaseDriver');
$db->setQuery("call StoredProcedure_2"); // <--- error occurs here
$results2 = $db->loadObjectList();
...foreach to create the $dropdown_2 object
return $dropdown_2;
}
public static function GetDropdown3($name, $details)
{
$db = Factory::getContainer()->get('DatabaseDriver');
$db->setQuery("call StoredProcedure_3");
$results3 = $db->loadObjectList();
...foreach to create the dropdown_3 object
return $dropdown_3;
}
public static function GetDropdown4($name, $details)
{
$db = Factory::getContainer()->get('DatabaseDriver');
$db->setQuery("call StoredProcedure_3");
$results4 = $db->loadObjectList();
...foreach to create the dropdown_4 object
return $dropdown_4;
}
Expected result
In Joomla 3 this code would output the 4 dropdown objects I need for the module. In Joomla 5 (and I assume Joomla 4) it is not possible to run back-to-back-to-back functions like this calling a stored procedure.
Actual result
Actual result is I receive this error:
2014 - Commands out of sync; you can't run this command now
System information (as much as possible)
Joomla version: 5.0.2
PHP version: 8.2.9
MySQL version: 8.0.28
DB Type: MySQLi
Server: AWS Linux 2023
Additional comments
Important: Changing the DB type in Joomla to MySQL (PDO) solves the problem. When I run the page containing the module after changing the DB type to MySQL (PDO) it runs as expected with no errors. However, I would prefer to use MySQLi if possible.
Researching the issue, it appears to be related to prepared statements in PHP. My understanding is that MySQL (PDO) does not use prepared statements and probably that is why it works correctly.
Let me know what else you need to review this case. Thanks.