Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2381

Joomla! 5.x Coding • MySQL Error -- 2014 - Commands out of sync; you can't run this command now

$
0
0
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.

Here's an example of the code in my helper.php file.

Code:

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 objectreturn $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 objectreturn $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 objectreturn $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 objectreturn $dropdown_4;}
From the info I have found on Google about this error it seems to suggest there is a conflict between the result sets that two or more results are active at the same time. The suggestion to fix the issue was to use the freeResult() method. However, when I tried that I received an error that I was trying to access a protected method and I don't know how to get around that.

Any suggestions? I've tried everything I can find.

Thanks in advance!

Statistics: Posted by mb87 — Thu Jan 18, 2024 6:16 pm



Viewing all articles
Browse latest Browse all 2381

Trending Articles