An error has occurred: 0 Call to undefined method Joomla\Database\Mysqli\MysqliDriver::query()

After migrating any website from Joomla 3.x to Joomla 4.x, we encounter the aforementioned issue since Joomla 4.x no longer supports the query() method. Additionally, if a plugin is updated from a Joomla 3.x version to a Joomla 4.x version, this can also happen. In its place, we must use the execute() method. Examining the example code below, let me explain:

Joomla 3.x:

$db = & JFactory::getDBO();
$db->setQuery("SELECT * FROM TABLE_NAME");
$db->query();

For Joomla 3.x, the above code was sufficient, but for Joomla 4.x, we must use the following code.

Joomla 4.x:

$db = & JFactory::getDBO();
$db->setQuery("SELECT * FROM TABLE_NAME");
$db->execute();

because in the Joomla 4.x version, execute() substituted query() method.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart