.
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 interface. 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 old DBperl's, 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.
However, some DBI modules have DBperl emulation layers, so, DBD::Oracle for example 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 the corresponding DBI calls.
Here's a table of emulation layer information:
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:
The Comprehensive Perl Archive Network resources should be used for retrieving up-to-date versions of the drivers. Local CPAN sites may be accessed via Tom Christiansen's splendid CPAN multiplexer program located at:
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:
There are two specifications available at this link, the new DBI Draft Specification which is a rapidly evolving document as Tim Bunce and the development team drive towards a stable interface, and the old historical DBperl Specification out of which the current DBI interface evolved.
The latter document should be regarded as being of historical interest only and should not serve as a programming manual, or authoratative in any sense. However, it is still a very useful reference source.
command.
This may be more convenient to persons not permanently, or conveniently, connected to the Internet but the document may not be the latest version.
This will produce an updated copy of the original oraperl man page written by Kevin Stock for perl4. The oraperl API is fully listed and described there.
Users with the Tk module installed may be interested to learn there is a
Tk-based POD reader available called tkpod
, which formats POD in a convenient
and readable way.
There are a series of occasional rambles from various people on the DBI mailing lists who, in an attempt to clear up a simple point, end up drafting fairly comprehensive documents. These are quite often varying in quality, but do provide some insights into the workings of the interfaces.
Here is the putative table of contents for the book.
If you cannot successfully use the WWW form on the above page, please subscribe to the list in the following manner:
Where 'dbi-XXX' is the name of the mailing list you are interested in. But note that your request will be handled by a human and may take some time.
The lists that users may participate in are:
Searchable hypermail archives of the three mailing lists, and some of the much older traffic have been set up for users to browse.
As per the US archive above.
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:
perl -V
), module
version and DBI version.
We tend to have real jobs to do, and we do read the mailing lists for
problems. Besides, we may not have access to <I If you are planning to email the author, please furnish as much information
as possible, ie:
.
Recent
DBI
and DBD::Oracle modules will build and work out-of-the-box
on Win32 with the standard perl 5.004 (or later) version of perl.
If you have to use the old non-standard ActiveWare perl port you can't use
the standard DBI and DBD::Oracle modules out-of-the-box. Details of the
changes required and pre-patched versions can be found at:
Supplied with DBI-0.79 ( and later ) is an experimental DBI 'emulation layer'
for the Win32::ODBC module. It's called
DBI::W32ODBC
and is,
at the moment, very minimal. You will need the Win32::ODBC module
available from:
Given its status, problem reports without fixes are likely to be ignored.
You will also need the Win32 DBI patch kit as supplied by Jeff Urlwin,
which you can locate by reading the previous question's answer.
To get back to the question, theoretically, yes, you can access Microsoft
Access and SQL-Server databases from DBI via ODBC!
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.
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.
To sum up, DBM is a perfectly satisfactory solution for essentially read-only
databases, or small and simple datasets with a single user. However,
for more powerful and scaleable datasets, not to mention robust
transactional locking, users are recommended to use
DBI
.
provided you have
DBD::mSQL
correctly installed.
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:
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 the Oracle RDBMS.
Oracle's WWW site is an excellent source of more information.
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:
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.
DBI reflects a generic API that will work for most databases, and has
no database-specific functionality defined.
However, driver authors may, if they so desire, include hooks to database-specific
functionality through the
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.
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:
The mod_perl module can be downloaded from CPAN via:
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:
The To solve this problem, set the environment for your database in a Similarly, you should check your The ``Idiot's Guide To Solving Perl / CGI Problems'' can be located at:
as can the ``Perl CGI Programming FAQ''. Read BOTH these documents
carefully! They will probably save you many hours of work.
For some OCI example code for Oracle that has multi-threaded
For example, assuming that you have created a stored procedure within
an Oracle database, you can use
Note the error checking, it may seem like extra work but it'll probably save
you hours in the long run. See $sth->{RaiseError} and $sth->{printError}
in the DBI docs for easier ways to get the same effect.
Some drivers, therefore, support database creation and deletion through
the private
but when queried back, the
Software developers should note that the However, some organizations are providing either technical support or
training programs on DBI. The present author has no knowledge as
to the quality of these services. The links are included for reference
purposes only.
for more details.
This document is Copyright (c)1997 Alligator Descartes. All rights reserved.
Permission to distribute this document, in full or in part, via email,
Usenet, ftp archives or http is granted providing that no charges are involved,
reasonable attempt is made to use the most current version and all credits
and copyright notices are retained ( the
AUTHOR
and
COPYRIGHT
sections ).
Requests for other distribution rights, including incorporation into
commercial products, such as books, magazine articles or CD-ROMs should be
made to Alligator Descartes <descarte@hermetica.com>.
.
Remember, the more information you send us, the quicker we can track .problems down. If you send us no useful information, expect nothing back.
Platform and Driver Issues
3.1 What's the difference between ODBC and DBI?
Good question! To be filled in more detail! Meanwhile see the notes at the
end of the DBI README file.
3.2 Is DBI supported under Windows 95 / NT platforms?
Finally, yes! Jeff Urlwin has been working diligently on building
DBI
and DBD::Oracle 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.
3.3 Can I access Microsoft Access or SQL-Server databases with DBI?
3.4 Is the a DBD for <insert favourite database here>?
Is is listed on the DBI drivers page?
3.5 What's DBM? And why should I use DBI instead?
Extracted from ``
DBI - The Database Interface for Perl 5
'':
3.6 When will mSQL-2 be supported?
As of DBD::mSQL-0.61, there has been support for mSQL-2.
However, there is no real support for any of the new methods added to the
core mSQL library regarding index support yet. These are forthcoming
and will be accessible via func()
methods private to
DBD::mSQL
.
You can read more about these private methods in the
DBD::mSQL
POD
that can be found by typing:
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.
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.
func()
method defined in the DBI API.
Script developers should note that use of functionality provided via
the func()
methods is unlikely to be portable across databases.
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.
4.2 How do I get faster connection times with DBD::Oracle and CGI?
httpd
maintains a pool of httpd
children to service client
requests.
httpd
children. The CGI, DBI, and your
other favorite modules can be loaded at the startup of each child. These
modules will not be reloaded unless changed on disk.
4.3 How do I get persistent connections with DBI and CGI?
httpd
child. If your application is based on a
single database user, this connection can be started with each child.
Currently, database connections cannot be shared between httpd
children.
4.4 ``My perl script runs from the command line, but fails under the
Basically, a good chance this is occurring is due to the fact that the user
that you ran it from the command line as has a correctly configured set of
environment variables, in the case of DBD::Oracle, variables like
httpd
!'' Why?$ORACLE_HOME
, $ORACLE_SID
or TWO_TASK
.
httpd
process usually runs under the user id of nobody
,
which implies there is no configured environment. Any scripts attempting to
execute in this situation will correctly fail.
BEGIN { }
block at the top of your script. This will generally solve the problem.
httpd
error logfile for any clues, as
well as the very valuable ``Idiot's Guide To Solving Perl / CGI Problems''
and ``Perl CGI Programming FAQ'' for further information. It is
unlikely the problem is DBI-related.
5.1 Can I do multi-threading with DBI?
As of the current date of this FAQ ( see top of page ), no. perl
does not support multi-threading. However, multi-threading is expected to
become part of the perl core distribution as of version 5.005, which implies
that DBI may support multi-threading fairly soon afterwards.
SELECT
statements, see:
5.2 How do I handle BLOB data with DBI?
To be written.
5.3 How can I invoke stored procedures with DBI?
There is currently no standard way to call stored procedures with DBI.
However, if the database lets you use SQL to call stored procedures
then the DBI and DBD driver probably will to.
$dbh
->do()
to immediately execute
the procedure:
5.4 How can I get return values from stored procedures with DBI?
5.5 How can I create or drop a database with DBI?
Database creation and deletion are concepts that are too abstract
to be adequately supported by DBI. For example, Oracle does not support the
concept of dropping a database at all! Also, in Oracle, the database
server essentially is the database, whereas in mSQL, the
server process runs happily without any databases created in it. The
problem is too disparate to attack easily.
func()
methods. You should check the documentation for
the drivers you are using to see if they support this mechanism.
5.6 How can I
To be written. See the commit
or rollback
a statement with DBI?commit
or rollback
methods in the DBI docs.
5.7 How are
NULL
values handled by DBI?NULL
values in DBI are specified to be treated as the value undef
.
NULL
s can be inserted into databases as NULL
, for example:
NULL
s should be tested against undef
.
This is standard across all drivers.
5.8 What are these
The func()
methods all about?func()
method is defined within DBI as being an entry point
for database-specific functionality, eg, the ability to create or
drop databases. Invoking these driver-specific methods is simple, for example,
to invoke a createDatabase
method that has one argument, we would
write:
func()
methods are
non-portable between databases.
Support and Training
The Perl5 Database Interface is FREE software. IT COMES WITHOUT WARRANTY
OF ANY KIND. See the DBI README and DBI documentation for more details.
Commercial Support
.
Training
No training programs are known at this time.
Other References
In this section, we present some miscellaneous WWW links that may be of
some interest to DBI users. These are not verified and may result in
unknown sites or missing documents.
AUTHOR
Alligator Descartes <descarte@hermetica.com>
COPYRIGHT
This document is Copyright (c)1994-1997 Alligator Descartes, with portions
Copyright (c)1994-1997 their original authors. This module is released under
the 'Artistic' license which you can find in the perl distribution.
Alligator Descartes - Hermetica