Forums / Developer / zeta components db handler with ini settings

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

zeta components db handler with ini settings

Author Message

Benjamin Choquet

Wednesday 30 March 2011 7:58:56 am

Hi,

I'm willing to use to use the db schema zeta component which seems far more powerful than the Exponential one but Exponential db interface is not compatible.

I'm wondering if Exponential API makes it possible to instantiate a ezcDBHandler using DatabaseSettings defined in site.ini. Has anyone tried that before ?

Nicolas Pastorino

Wednesday 30 March 2011 10:40:21 am

Hi Benjamin,

The ezcDBHandler interface and eZDBInterface's are different. Even if you manage to get an ezcDBHandler session instantiated, the methods called will differ, causing Fatal errors. Achieveing this would require more in-depth changes, imho.

In your custom extensions though, to access external tables, you can use Zeta Components for this. I do this very often, and i love it :)

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Benjamin Choquet

Thursday 31 March 2011 12:24:00 am

Hi Nicolas, thanks for your reply.

The thing is I'm developing an upgrade script which is totally unrelated to eZ's execution so I wouldn't mind using a totally different API. My need is more of a ezcDbFactory wrapper loading site.ini's DatabaseSettings block and calling the component's factory but I gather nothing exists at the time.

I guess I'll have to make one. Any pit traps I should beware when it comes to db instantiation ?

Gaetano Giunta

Thursday 31 March 2011 1:14:54 am

If you do that, please share the results of your work - I guess many ppl will appreciate it.

About using ezc dbschema: it os not 100% compatible when using oracle (eg. the names of sequences used for autoincrement cols is different, as well as the way it handles quoting of identifiers). Any improvement in that area is of course welcome, too

Principal Consultant International Business
Member of the Community Project Board

Nicolas Pastorino

Thursday 31 March 2011 2:32:33 am

Hi Benjamin, Gaetano,

Here is an initialization stub, easily embeddable in a dedicated method :

public static function initializeEzcPersistentSession()
    {
        if ( !self::$initialized )
        {
            // @FIXME : make this code DBMS-agnostic
            $dbURI = "mysql://";
            $dbURI .= eZINI::instance()->variable( 'DatabaseSettings', 'User' );
            $dbURI .= ':' . eZINI::instance()->variable( 'DatabaseSettings', 'Password' );
            $dbURI .= '@' . eZINI::instance()->variable( 'DatabaseSettings', 'Server' );
            $dbURI .= '/' . eZINI::instance()->variable( 'DatabaseSettings', 'Database' );

            ezcDbInstance::set( ezcDbFactory::create( $dbURI ) );
            $session = new ezcPersistentSession( ezcDbInstance::get(),
                                                 new ezcPersistentCacheManager( new ezcPersistentCodeManager( "extension/ezforumtools/classes/po/" ) ) );
            ezcPersistentSessionInstance::set( $session ); // set default session
            self::$initialized = true;
        }
        return ezcPersistentSessionInstance::get();
    }

and here is a usage stub :

$session = eZForumTools::initializeEzcPersistentSession();
$q = $session->createFindQuery( 'eZForumModeratedEntry' );
$q->where( $q->expr->eq( 'contentObjectId', $q->bindValue( $objectId ) ) );
return $session->find( $q, 'eZForumModeratedEntry' );

These are stubs, to be wrapped in lazy initialization ideally,
Hope it helps,
Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Benjamin Choquet

Wednesday 18 May 2011 9:56:34 am

For those interested I finally made a helper method which works fine for a classic mySQL install.

Gist is available at https://gist.github.com/978982

Feel free to improve it :)