Extending DB Class Joomla 3/4

Be informed that this forum is not an official support forum for Joomla! 4.0. Any issues regarding Joomla! 4.0 must be reported at https://issues.joomla.org/.

Joomla 4.0 is still in Beta stage. This forum should be used for sharing information about Joomla! 4.0.

Moderator: ooffick

Forum rules
Locked
mirko4u
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Sep 07, 2009 9:57 am

Extending DB Class Joomla 3/4

Post by mirko4u » Tue Jul 13, 2021 7:38 am

Hello forum!

I have developed custom pages in a Joomla 3 portal, which access an external mysql DB. To access the external db from these custom scripts, in order to add custom code to execute at each access, I have defined an additional joomla DB driver, extending the native one:

Code: Select all

<?php

/**
 MySQLi database driver CUSTOM
 */
class JDatabaseDriverMysqlibz extends JDatabaseDriverMysqli
{
	public function executeBz()
	{
		// bla bla custom code
		// .....
		
		return parent::execute();
	}
}
then I create an instance of the DB using the custom driver

Code: Select all

//---------------- Set custom database driver (the db used for functions NOT related to the joomla portal)
$option = array();
$option['driver'] = 'MysqliBz'; // Database driver name
$option['host'] = 'XXXXHOST'; // Database host name
$option['user'] = 'XXXUSR'; // User for database authentication
$option['password'] = 'XXXPWD'; // Password for database authentication
$option['database'] = 'XXXDB'; // Database name
$option['prefix'] = ''; // Database prefix (may be empty) 

$customDBinstance = JDatabaseDriver::getInstance( $option );

and everything works well, if I use the custom method executeBz when accessing the DB.


Now, I am porting this solution to a Joomla 4 portal, but it is not working.
What I get is the error:
Unable to load Database Driver: bz
thrown at:
JROOT/libraries/vendor/joomla/database/src/DatabaseFactory.php:46

The DatabaseFactory scripts looks for a class named :
Joomla\Database\Bz\BzDriver

How can I extend the native DB class to create my custom class extension?

Any suggestion is appreciated.
Thank you!
M

Locked

Return to “Joomla! 4 Related”