No Code Attached Yet
avatar mahagr
mahagr
31 Aug 2021

Steps to reproduce the issue

use Joomla\CMS\Menu\MenuItem;

$db = \JFactory::getDbo();
$query = $db->getQuery(true)
    ->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language')
    ->select($db->quoteName('m.browserNav') . ', m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id')
    ->select('e.element as component')
    ->from('#__menu AS m')
    ->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')
    ->where('m.menutype = ' . $db->quote($menutype))
    ->where('m.parent_id > 0')
    ->where('m.client_id = 0')
    ->where('m.published >= 0')
    ->order('m.lft');

// Set the query
$db->setQuery($query);

$list = $db->loadObjectList('id', MenuItem::class);

Expected result

The query should work just as it worked in Joomla 3.9/3.10.

Actual result

Exception: Unknown fetch type '8'. This seems to happen when using mysqli but not when using dbo.

System information (as much as possible)

PHP 8.0.10 / 7.4.23

Additional comments

Following workaround works (replace the last line):

$list = [];
foreach ($db->loadAssocList('id') as $id => $data) {
    $list[$id] = new MenuItem($data);
}
avatar mahagr mahagr - open - 31 Aug 2021
avatar joomla-cms-bot joomla-cms-bot - change - 31 Aug 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 31 Aug 2021
avatar mahagr mahagr - change - 31 Aug 2021
The description was changed
avatar mahagr mahagr - edited - 31 Aug 2021
avatar mahagr
mahagr - comment - 31 Aug 2021

Bug is located in MysqliStatement::fetch() method. I compared it with SqlsrvStatement::fetch() which takes the constant into consideration.

avatar richard67
richard67 - comment - 31 Aug 2021

... which takes the constant into consideration.

@mahagr Which constant do you mean? And I think the issue should be reported here: https://github.com/joomla-framework/database as it's in the database driver. Or am I wrong?

avatar mahagr
mahagr - comment - 1 Sep 2021

FetchMode::CUSTOM_OBJECT isn't being handled. I will make a new issue to the DB repository.

avatar mahagr
mahagr - comment - 1 Sep 2021

Please do not close this issue until you have updated the framework in CMS as it's a B/C break in Joomla.

avatar richard67
richard67 - comment - 1 Sep 2021

Thanks. Yes, we'll leave it open as reminder.

avatar mahagr
mahagr - comment - 2 Sep 2021

@richard67 See the response in the Joomla Framework issue.

avatar richard67
richard67 - comment - 2 Sep 2021

@richard67 See the response in the Joomla Framework issue.

@mahagr Yes, I saw. Here the link for reference for other readers: joomla-framework/database#254 (comment) . I'm not sure now what to do with this issue here.

avatar mahagr
mahagr - comment - 2 Sep 2021

Do we have the same version of Framework in Joomla 3.10?

I think the best way to deal with the issue is to have a better error message instead of the one from above. It is a compatibility issue for sure; older versions of Joomla accepted custom classes with all DB engines. Luckily it is something that is generally very easy to fix, but in my case, I totally missed it as I'm using PDO for testing.

Also, should Joomla! 4 use PDO by default?

avatar richard67
richard67 - comment - 2 Sep 2021

3.10 and 4 use different versions of the Framework. Why PDO hasn't been chosen as default for new installations I don't know.

avatar mahagr
mahagr - comment - 2 Sep 2021

@mbabker Any idea why Joomla 4 doesn't use PDO by default?

avatar joomdonation joomdonation - change - 16 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-16 08:49:37
Closed_By joomdonation
avatar joomdonation joomdonation - close - 16 Nov 2022
avatar joomdonation
joomdonation - comment - 16 Nov 2022

Base on the discussion I read from the framework repo joomla-framework/database#254 (comment) , there would be no change to support the issue mentioned here. Anyone has this issue, please use the provided workaround:

$list = [];
foreach ($db->loadAssocList('id') as $id => $data) {
    $list[$id] = new MenuItem($data);
}

With that said, I'm closing this issue here.

Add a Comment

Login with GitHub to post a comment