#82 Generic modules do not allow multiple drivers

open
Pear Module (3)
5
2007-03-28
2007-03-13
Daniel
No

Due to a design constraint, it is currently impossible to use two different database drivers in the same PHP script.

This is due to the fact that generic modules classes will not be included (and correctly created) for the second (and subsequent) database drivers used.

I think this is very limiting for inter-database works and has already broken some features that were previously working in adoDB lite versions which did not feature the generic modules.

Would it be possible to have generic modules as normal modules for each driver? Of course they would share the same API but the class name would be different leading to a correctly instanced generic module for each driver.

Thank you

Discussion

  • Mark Dickenson

    Mark Dickenson - 2007-03-13
    • status: open --> closed
     
  • Daniel

    Daniel - 2007-03-13
    • status: closed --> pending
     
  • Daniel

    Daniel - 2007-03-13

    Logged In: YES
    user_id=799761
    Originator: YES

    I had already tried that change but sorry, it always gives me:

    > Fatal error: Cannot redeclare class pear_ADOConnection in C:\wwwroot\***\adodb_lite\generic_modules\pear_module.inc on line 128
    >

    So I submitted this bug report

     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     
  • Daniel

    Daniel - 2007-03-28
    • status: closed --> open
     
  • Steve Clay

    Steve Clay - 2007-07-17

    Logged In: YES
    user_id=1794708
    Originator: NO

    The limitation (which should be documented) is that each generic module can be used with only one driver.

    The workaround is a hack, but is incredibly simple: if you need a generic module that has already been used, you just duplicate the module, changing the name slightly in the filename and all references to classnames within. So to use the pear module with a second database driver, you copy pear_module.inc to pear2_module.inc, then open the copy and replace all instances of "pear_" with "pear2_". Your second driver should then use the module "pear2".

    The limitation is due to PHP's lack of multiple-inheritance and mix-ins. ADOdb currently weasles around this by dynamically creating (via eval) intermediate adapter classes [1] to pull module classes into the inheritance chain. There are several ways to implement mix-ins [2], but all require PHP5. In PHP4, the best you could do would be to copy the code of each mix-in (reading the filesystem), combine, and and eval it into a new class. This would work, but you'd lose all benefit of opcode caching. The current system has to use eval, but at least allows the compiled code of each driver and module to be cached.

    [1] http://us.php.net/manual/en/keyword.extends.php#72661
    [2] http://www.achievo.org/blog/archives/46-Mixins-in-PHP.html

     
  • Steve Clay

    Steve Clay - 2007-07-17

    Logged In: YES
    user_id=1794708
    Originator: NO

    Actually, the workaround I described (using eval and filesystem reads) *could* be rolled into the ADOdb with minimal modifications. For most users (not running into this problem), almost no additional code would run. For those who need it, it would save them the hassle of manually building another file and using something like "pear2" in the DNS string.

    The idea is to use class_exists($mod . '_EXTENDER') to see if the module was already loaded, and, if so, use its source code to dynamically create the class {$mod}2_ADOConnection', then set $last_module = $mod . '2'. (If 2 is used, we go to 3, and so on.)

     
  • Daniel

    Daniel - 2007-07-19

    Logged In: YES
    user_id=799761
    Originator: YES

    @mrclay: looks like this project is abandoned - the author did not answer to me.

    I would be interested in fixing this bad behaviour, I would also consider reverting some code to some older revision (which did not have this bad behaviour); would you collaborate with me to fix the bug?

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks