ActivePerl Documentation
|
NAMEDBI::FAQ -- The Frequently Asked Questions for the Perl5 Database Interface [an error occurred while processing this directive]Last updated: December 30th, 1998
SUPPORTED PLATFORMS
SYNOPSIS
perldoc DBI::FAQ
VERSIONThis document is currently at version 0.37, as of December 30th, 1998.
DESCRIPTIONThis document serves to answer the most frequently asked questions on both the DBI Mailing Lists and personally to members of the DBI development team.
Basic Information & Information Sources
1.1 What is DBI, DBperl, Oraperl and *perl?To quote Tim Bunce, the architect and author of DBI:
``DBI is a database access Application Programming Interface (API)
for the Perl Language. The DBI API Specification defines a set
of functions, variables and conventions that provide a consistent
database interface independant of the actual database being used.''
In simple language, the DBI interface allows users to access multiple database types transparently. So, if you connecting to an Oracle, Informix, mSQL, Sybase or whatever database, you don't need to know the underlying mechanics of the 3GL layer. The API defined by DBI will work on all these database types. A similar benefit is gained by the ability to connect to two different databases of different vendor within the one perl script, ie, I want to read data from an Oracle database and insert it back into an Informix database all within one program. The DBI layer allows you to do this simply and powerfully. Here's a diagram that demonstrates the principle:
DBperl is the old name for the interface specification. It's usually now used to denote perl4 modules on database interfacing, such as, oraperl, isqlperl, ingperl and so on. These interfaces didn't have a standard API and are generally not supported. Here's a list of DBperl modules, their corresponding DBI counterparts and support information. Please note, the author's listed here generally do not maintain the DBI module for the same database. These email addresses are unverified and should only be used for queries concerning the perl4 modules listed below. DBI driver queries should be directed to the dbi-users mailing list.
Module Name Database Required Author DBI
----------- ----------------- ------ ---
Sybperl Sybase Michael Peppler DBD::Sybase
<mpeppler@itf.ch>
Oraperl Oracle 6 & 7 Kevin Stock DBD::Oracle
<dbi-users@isc.org>
Ingperl Ingres Tim Bunce & DBD::Ingres
Ted Lemon
<dbi-users@isc.org>
Interperl Interbase Buzz Moschetti DBD::Interbase
<buzz@bear.com>
Uniperl Unify 5.0 Rick Wargo None
<rickers@coe.drexel.edu>
Pgperl Postgres Igor Metz DBD::Pg
<metz@iam.unibe.ch>
Btreeperl NDBM John Conover SDBM?
<john@johncon.com>
Ctreeperl C-Tree John Conover None
<john@johncon.com>
Cisamperl Informix C-ISAM Mathias Koerber None
<mathias@unicorn.swi.com.sg>
Duaperl X.500 Directory Eric Douglas None
User Agent
However, some DBI modules have DBperl emulation layers, so, DBD::Oracle comes with an Oraperl emulation layer, which allows you to run legacy oraperl scripts without modification. The emulation layer translates the oraperl API calls into DBI calls and executes them through the DBI switch. Here's a table of emulation layer information:
Module Emulation Layer Status
------ --------------- ------
DBD::Oracle Oraperl Complete
DBD::Informix Isqlperl Under development
DBD::Ingres Ingperl Complete?
DBD::Sybase Sybperl Working? ( Needs verification )
DBD::mSQL Msqlperl Experimentally released with
DBD::mSQL-0.61
The Msqlperl emulation is a special case. Msqlperl is a perl5 driver for mSQL databases, but does not conform to the DBI Specification. It's use is being deprecated in favour of DBD::mSQL. Msqlperl may be downloaded from CPAN via:
http://www.perl.com/cgi-bin/cpan_mod?module=Msqlperl
1.2. Where can I get it from?The Comprehensive Perl Archive Network resources should be used for retrieving up-to-date versions of the DBI and drivers. CPAN may be accessed via Tom Christiansen's splendid CPAN multiplexer program located at:
http://www.perl.com/CPAN/
For more specific version information and exact URLs of drivers, please see the DBI drivers list and the DBI module pages which can be found on:
http://www.arcana.co.uk/technologia/perl/DBI
1.3. Where can I get more information?There are a few information sources on DBI.
Compilation Problems
2.1. Compilation problems or ``It fails the test!''First off, consult the README for that driver in case there is useful information about the problem. It may be a known problem for your given architecture and operating system or database. You can check the README files for each driver in advance online at:
http://www.arcana.co.uk/technologia/perl/DBI
If it's a known problem, you'll probably have to wait till it gets fixed. If you're really needing it fixed, try the following:
Platform and Driver Issues
3.1 What's the difference between ODBC and DBI?In terms of architecture - not much: Both define programming interfaces. Both allow multiple drivers to be loaded to do the actual work. In terms of easy of use - much: The DBI is a 'high level' interface that, like Perl itself, strives to make the simple things easy while still making the hard things possible. The ODBC is a 'low level' interface. All nuts-bolts-knobs-and-dials. Now there's an ODBC driver for the DBI (DBD::ODBC) the ``What's the difference'' question is more usefully rephrased as:
3.2 What's the difference between Win32::ODBC and DBD::ODBC?The DBI, and thus DBD::ODBC, has a different philosophy from the Win32::ODBC module: The Win32::ODBC module is a 'thin' layer over the low-level ODBC API. The DBI defines a simpler 'higher level' interface. The Win32::ODBC module gives you access to more of the ODBC API. The DBI and DBD::ODBC give you access to only the essentials. (But, unlike Win32::ODBC, the DBI and DBD::ODBC do support parameter binding and multiple prepared statements which reduces the load on the database server and can dramatically increase performance.) The Win32::ODBC module only works on Win32 systems. The DBI and DBD::ODBC are very portable and work on Win32 and Unix. The DBI and DBD::ODBC modules are supplied as a standard part of the Perl 5.004 binary distribution for Win32 (they don't work with the older, non-standard, ActiveState port). Scripts written with the DBI and DBD::ODBC are faster than Win32::ODBC on Win32 and are trivially portable to other supported database types. The DBI offers optional automatic printing or die()ing on errors which makes applications simpler and more robust. The current DBD::ODBC driver version 0.16 is new and not yet fully stable. A new release is due soon [relative to the date of the next TPJ issue :-] and will be much improved and offer more ODBC functionality. To summarise: The Win32::ODBC module is your best choice if you need access to more of the ODBC API than the DBI gives you. Otherwise, the DBI and DBD::ODBC combination may be your best bet.
3.3 Is DBI supported under Windows 95 / NT platforms?Finally, yes! Jeff Urlwin has been working diligently on building DBI and DBD::ODBC under these platforms, and, with the advent of a stabler perl and a port of MakeMaker, the project has come on by great leaps and bounds. The DBI and DBD::Oracle Win32 ports are now a standard part of DBI, so, downloading DBI of version higher than 0.81 should work fine as should using the most recent DBD::Oracle version.
3.4 Can I access Microsoft Access or SQL-Server databases with DBI?Yes, use the DBD::ODBC driver.
3.5 Is the a DBD for <insert favourite database here>?Is is listed on the DBI drivers page?
http://www.arcana.co.uk/technologia/perl/DBI
If not, no. A complete absence of a given database driver from that page means that no-one has announced any intention to work on it, not that such a driver is impossible to write. A corollary of the above statement implies that if you see an announcement for a driver not on the above page, there's a good chance it's not actually a DBI driver, and may not conform to the specifications. Therefore, questions concerning problems with that code should not really be addressed to the DBI Mailing Lists.
3.6 What's DBM? And why should I use DBI instead?Extracted from ``DBI - The Database Interface for Perl 5'':
``UNIX was originally blessed with simple file-based ``databases'', namely
the dbm system. dbm lets you store data in files, and retrieve
that data quickly. However, it also has serious drawbacks.
File Locking
The dbm systems did not allow particularly robust file locking
capabilities, nor any capability for correcting problems arising through
simultaneous writes [ to the database ].
Arbitrary Data Structures
The dbm systems only allows a single fixed data structure:
key-value pairs. That value could be a complex object, such as a
[ C ] struct, but the key had to be unique. This was a large
limitation on the usefulness of dbm systems.
However, dbm systems still provide a useful function for users with
simple datasets and limited resources, since they are fast, robust and
extremely well-tested. Perl modules to access dbm systems have now
been integrated into the core Perl distribution via the
AnyDBM_File module.''
To sum up, DBM is a perfectly satisfactory solution for essentially read-only databases, or small and simple datasets. However, for more scaleable dataset handling, not to mention robust transactional locking, users are recommended to use a more powerful database engine via DBI.
3.7 What database do you recommend me using?This is a particularly thorny area in which an objective answer is difficult to come by, since each dataset, proposed usage and system configuration differs from person to person. From the current author's point of view, if the dataset is relatively small, being tables of less than 1 million rows, and less than 1000 tables in a given database, then mSQL is a perfectly acceptable solution to your problem. This database is extremely cheap, is wonderfully robust and has excellent support. More information is available on the Hughes Technology WWW site at:
http://www.hughes.com.au
You may also wish to look at MySQL which is a more powerful database engine that has a similar feel to mSQL.
http://www.tcx.se
If the dataset is larger than 1 million row tables or 1000 tables, or if you have either more money, or larger machines, I would recommend Oracle RDBMS. Oracle's WWW site is an excellent source of more information.
http://www.oracle.com
Informix is another high-end RDBMS that is worth considering. There are several differences between Oracle and Informix which are too complex for this document to detail. Information on Informix can be found on their WWW site at:
http://www.informix.com
In the case of WWW fronted applications, mSQL may be a better option due to slow connection times between a CGI script and the Oracle RDBMS and also the amount of resource each Oracle connection will consume. mSQL is lighter resource-wise and faster. These views are not necessarily representative of anyone else's opinions, and do not reflect any corporate sponsorship or views. They are provided as-is.
3.8 Is <insert feature here> supported in DBI?Given that we're making the assumption that the feature you have requested is a non-standard database-specific feature, then the answer will be no. DBI reflects a generic API that will work for most databases, and has no database-specific functionality. However, driver authors may, if they so desire, include hooks to database-specific
functionality through the
Programming Questions
4.1 Is DBI any use for CGI programming?In a word, yes! DBI is hugely useful for CGI programming! In fact, I would tentatively say that CGI programming is one of two top uses for DBI. DBI confers the ability to CGI programmers to power WWW-fronted databases to their users, which provides users with vast quantities of ordered data to play with. DBI also provides the possibility that, if a site is receiving far too much traffic than their database server can cope with, they can upgrade the database server behind the scenes with no alterations to the CGI scripts.
4.2 How do I get faster connection times with DBD::Oracle and CGI?
Contributed by John D. Groenveld
The Apache Using the Apache mod_perl module by Doug MacEachern, the perl
interpreter is embedded with the For more information on Apache, see the Apache Project's WWW site:
http://www.apache.org
The mod_perl module can be downloaded from CPAN via:
http://www.perl.com/cgi-bin/cpan_mod?module=Apache
4.3 How do I get persistent connections with DBI and CGI?
Contributed by John D. Groenveld
Using Edmund Mergl's Apache::DBI module, database logins are stored in a
hash with each of these Apache::DBI can be downloaded from CPAN via:
http://www.perl.com/cgi-bin/cpan_mod?module=Apache::DBI
4.4 ``When I run a perl script from the command line, it works, but, when I run it under the
|