2.3. Loading libdbi at runtime

The generic example shown in the previous section assumed that the program is linked against libdbi. This is in fact the recommended way to add libdbi functionality to your programs. However, there are situations where this approach will not work. Some programs are designed to load modules at runtime to extend their capabilities. A well-known example is the web server Apache, which uses loadable modules to custom-tailor its capabilities. If such a module were to use libdbi, we'd look at the following pattern:

Parent => dl_open(module) => dl_open(libdbi) => dl_open(driver)

Both libdbi and the drivers have to be loaded using the dl_open function as it is not possible to link the dynamically loaded module against libdbi. For this pattern to work, the drivers need a little tweak, like this:

~/libdbi-drivers #./configure --enable-libdbi --with-mysql

Drivers built with this option are supposed to work both with the procedure shown above and with the generic procedure shown in the previous section. This has been tested on Linux, FreeBSD, and Cygwin. You may want to test the drivers on other platforms in both modes to avoid surprises.