home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / FAQ.pm < prev    next >
Encoding:
Perl POD Document  |  2002-06-14  |  36.1 KB  |  983 lines

  1. ###
  2. ### $Id: FAQ.pm,v 11.2 2001/08/24 22:10:44 timbo Exp $
  3. ###
  4. ### DBI Frequently Asked Questions POD
  5. ###
  6. ### Copyright section reproduced from below.
  7. ###
  8. ### This document is Copyright (c)1994-2000 Alligator Descartes, with portions
  9. ### Copyright (c)1994-2000 their original authors. This module is released under
  10. ### the 'Artistic' license which you can find in the perl distribution.
  11. ### 
  12. ### This document is Copyright (c)1997-2000 Alligator Descartes. All rights reserved.
  13. ### Permission to distribute this document, in full or in part, via email,
  14. ### Usenet, ftp archives or http is granted providing that no charges are involved,
  15. ### reasonable attempt is made to use the most current version and all credits
  16. ### and copyright notices are retained ( the I<AUTHOR> and I<COPYRIGHT> sections ).
  17. ### Requests for other distribution rights, including incorporation into 
  18. ### commercial products, such as books, magazine articles or CD-ROMs should be
  19. ### made to Alligator Descartes <I<http://www.symbolstone.org/descarte/contact.html>>.
  20. ### 
  21. ### $Log: FAQ.pm,v $
  22. # Revision 11.2  2001/08/24  22:10:44  timbo
  23. # *** empty log message ***
  24. #
  25. # Revision 10.8  2001/05/29  23:25:55  timbo
  26. # *** empty log message ***
  27. #
  28. # Revision 10.7  2001/03/28  14:52:07  timbo
  29. # Main checkin prior to 1.15 release
  30. #
  31.  
  32. package DBI::FAQ;
  33.  
  34. $VERSION = '0.38';
  35.  
  36. =head1 NAME
  37.  
  38. DBI::FAQ -- The Frequently Asked Questions for the Perl5 Database Interface
  39.  
  40. =for html
  41. <BODY BGCOLOR="#ffffff" TEXT="#000000" LINK="#3a15ff" ALINK="#ff0000" VLINK="#ff282d">
  42. <!--#include virtual="/technology/perl/DBI/templatetop.html" -->
  43. <CENTER>
  44. <FONT SIZE="+2">
  45. DBI Frequently Asked Questions v.0.38
  46. </FONT>
  47. <BR>
  48. <FONT SIZE="-1">
  49. <I>Last updated: February 8th, 2000</I>
  50. </FONT>
  51. </CENTER>
  52. <P>
  53.  
  54. =head1 SYNOPSIS
  55.  
  56.     perldoc DBI::FAQ
  57.  
  58. =head1 VERSION
  59.  
  60. This document is currently at version I<0.38>, as of I<February 8th, 2000>.
  61.  
  62. =head1 DESCRIPTION
  63.  
  64. This document serves to answer the most frequently asked questions on both
  65. the DBI Mailing Lists and personally to members of the DBI development team.
  66.  
  67. =head1 Basic Information & Information Sources
  68.  
  69. =head2 1.1 What is DBI, DBperl, Oraperl and *perl?
  70.  
  71. To quote Tim Bunce, the architect and author of DBI:
  72.  
  73.     ``DBI is a database access Application Programming Interface (API)
  74.       for the Perl Language. The DBI API Specification defines a set
  75.       of functions, variables and conventions that provide a consistent
  76.       database interface independant of the actual database being used.''
  77.  
  78. In simple language, the DBI interface allows users to access multiple database
  79. types transparently. So, if you connecting to an Oracle, Informix, mSQL, Sybase
  80. or whatever database, you don't need to know the underlying mechanics of the
  81. 3GL layer. The API defined by DBI will work on I<all> these database types.
  82.  
  83. A similar benefit is gained by the ability to connect to two I<different>
  84. databases of different vendor within the one perl script, I<ie>, I want
  85. to read data from an Oracle database and insert it back into an Informix
  86. database all within one program. The DBI layer allows you to do this simply
  87. and powerfully.
  88.  
  89.  
  90. =for html
  91. Here's a diagram that demonstrates the principle:
  92. <P>
  93. <CENTER>
  94. <IMG SRC="img/dbiarch.gif" WIDTH=451 HEIGHT=321 ALT="[ DBI Architecture ]">
  95. </CENTER>
  96. <P>
  97.  
  98. I<DBperl> is the old name for the interface specification. It's usually
  99. now used to denote perlI<4> modules on database interfacing, such as,
  100. I<oraperl>, I<isqlperl>, I<ingperl> and so on. These interfaces
  101. didn't have a standard API and are generally I<not> supported.
  102.  
  103. Here's a list of DBperl modules, their corresponding DBI counterparts and
  104. support information. I<Please note>, the author's listed here generally
  105. I<do not> maintain the DBI module for the same database. These email
  106. addresses are unverified and should only be used for queries concerning the
  107. perl4 modules listed below. DBI driver queries should be directed to the
  108. I<dbi-users> mailing list.
  109.  
  110.     Module Name    Database Required   Author          DBI
  111.     -----------    -----------------   ------          ---
  112.     Sybperl     Sybase              Michael Peppler DBD::Sybase
  113.                                     <mpeppler@itf.ch>
  114.     Oraperl     Oracle 6 & 7        Kevin Stock     DBD::Oracle
  115.                                     <dbi-users@perl.org>
  116.     Ingperl     Ingres              Tim Bunce &     DBD::Ingres
  117.                                     Ted Lemon
  118.                                     <dbi-users@perl.org>
  119.     Interperl   Interbase           Buzz Moschetti  DBD::Interbase
  120.                                     <buzz@bear.com>
  121.     Uniperl     Unify 5.0           Rick Wargo      None
  122.                                     <rickers@coe.drexel.edu>
  123.     Pgperl      Postgres            Igor Metz       DBD::Pg
  124.                                     <metz@iam.unibe.ch>
  125.     Btreeperl   NDBM                John Conover    SDBM?
  126.                                     <john@johncon.com>
  127.     Ctreeperl   C-Tree              John Conover    None
  128.                                     <john@johncon.com>
  129.     Cisamperl   Informix C-ISAM     Mathias Koerber None
  130.                                     <mathias@unicorn.swi.com.sg>
  131.     Duaperl     X.500 Directory     Eric Douglas    None
  132.                 User Agent
  133.  
  134. However, some DBI modules have DBperl emulation layers, so, I<DBD::Oracle>
  135. comes with an Oraperl emulation layer, which allows you to run legacy oraperl
  136. scripts without modification. The emulation layer translates the oraperl API
  137. calls into DBI calls and executes them through the DBI switch.
  138.  
  139. Here's a table of emulation layer information:
  140.  
  141.     Module            Emulation Layer     Status
  142.     ------          ---------------     ------
  143.     DBD::Oracle     Oraperl             Complete
  144.     DBD::Informix   Isqlperl            Under development
  145.     DBD::Ingres     Ingperl             Complete?
  146.     DBD::Sybase     Sybperl             Working? ( Needs verification )
  147.     DBD::mSQL       Msqlperl            Experimentally released with
  148.                                         DBD::mSQL-0.61
  149.  
  150. The I<Msqlperl> emulation is a special case. I<Msqlperl> is a perl5 driver
  151. for I<mSQL> databases, but does not conform to the DBI Specification. It's
  152. use is being deprecated in favour of I<DBD::mSQL>. I<Msqlperl> may be downloaded
  153. from CPAN I<via>:
  154.  
  155.     http://www.perl.com/cgi-bin/cpan_mod?module=Msqlperl
  156.  
  157. =head2 1.2. Where can I get it from?
  158.  
  159. The Comprehensive Perl Archive Network
  160. resources should be used for retrieving up-to-date versions of the DBI
  161. and drivers. CPAN may be accessed I<via> Tom Christiansen's splendid
  162. I<CPAN multiplexer> program located at:
  163.  
  164.     http://www.perl.com/CPAN/
  165.  
  166. For more specific version information and exact URLs of drivers, please see
  167. the DBI drivers list and the DBI module pages which can be found on:
  168.  
  169.     http://dbi.perl.org/
  170.     http://www.symbolstone.org/technology/perl/DBI
  171.  
  172. This list is automatically generated on a nightly basis from CPAN and should
  173. be up-to-date.
  174.  
  175. =head2 1.3. Where can I get more information?
  176.  
  177. There are a few information sources on DBI.
  178.  
  179. =over 4
  180.  
  181. =item I<"Programming the Perl DBI">
  182.  
  183. "Programming the Perl DBI" is the I<official> book on the DBI written by
  184. Alligator Descartes and Tim Bunce and published by O'Reilly & Associates.
  185. The book was released on February 9th, 2000.
  186.  
  187. The table of contents is:
  188.  
  189.     Preface
  190.     1. Introduction
  191.         From Mainframes to Workstations
  192.         Perl
  193.         DBI in the Real World
  194.         A Historical Interlude and Standing Stones
  195.     2. Basic Non-DBI Databases
  196.         Storage Managers and Layers
  197.         Query Languages and Data Functions
  198.         Standing Stones and the Sample Database
  199.         Flat-File Databases
  200.         Putting Complex Data into Flat Files
  201.         Concurrent Database Access and Locking
  202.         DBM Files and the Berkeley Database Manager
  203.         The MLDBM Module
  204.         Summary
  205.     3. SQL and Relational Databases
  206.         The Relational Database Methodology
  207.         Datatypes and NULL Values
  208.         Querying Data
  209.         Modifying Data Within Tables
  210.         Creating and Destroying Tables
  211.     4. Programming with the DBI
  212.         DBI Architecture
  213.         Handles
  214.         Data Source Names
  215.         Connection and Disconnection
  216.         Error Handling
  217.         Utility Methods and Functions
  218.     5. Interacting with the Database
  219.         Issuing Simple Queries
  220.         Executing Non-SELECT Statements
  221.         Binding Parameters to Statements
  222.         Binding Output Columns
  223.         do() Versus prepare()
  224.         Atomic and Batch Fetching
  225.     6. Advanced DBI
  226.         Handle Attributes and Metadata
  227.         Handling LONG/LOB Data
  228.         Transactions, Locking, and Isolation
  229.     7. ODBC and the DBI
  230.         ODBC -- Embraced and Extended
  231.         DBI -- Thrashed and Mutated
  232.         The Nuts and Bolts of ODBC
  233.         ODBC from Perl
  234.         The Marriage of DBI and ODBC
  235.         Questions and Choices
  236.         Moving Between Win32::ODBC and the DBI
  237.         And What About ADO?
  238.     8. DBI Shell and Database Proxying
  239.         dbish -- The DBI Shell
  240.         Database Proxying
  241.     A. DBI Specification
  242.     B. Driver and Database Characteristics
  243.     C. ASLaN Sacred Site Charter
  244.     Index
  245.  
  246. The book should be available from all good bookshops and can be ordered online
  247. either <I>via</I> O'Reilly & Associates
  248.  
  249.     http://www.oreilly.com/catalog/perldbi
  250.  
  251. or Amazon
  252.  
  253.     http://www.amazon.com/exec/obidos/ASIN/1565926994/dbi
  254.  
  255. =item I<POD documentation>
  256.  
  257. I<POD>s are chunks of documentation usually embedded within perl programs
  258. that document the code ``I<in place>'', providing a useful resource for
  259. programmers and users of modules. POD for DBI and drivers is beginning to
  260. become more commonplace, and documentation for these modules can be read
  261. with the C<perldoc> program included with Perl.
  262.  
  263. =over 4
  264.  
  265. =item The DBI Specification
  266.  
  267. The POD for the DBI Specification can be read with the:
  268.  
  269.     perldoc DBI
  270.  
  271. command. The Specification also forms Appendix A of "Programming the Perl
  272. DBI".
  273.  
  274. =item Oraperl
  275.  
  276. Users of the Oraperl emulation layer bundled with I<DBD::Oracle>, may read
  277. up on how to program with the Oraperl interface by typing:
  278.  
  279.     perldoc Oraperl
  280.  
  281. This will produce an updated copy of the original oraperl man page written by
  282. Kevin Stock for perl4. The oraperl API is fully listed and described there.
  283.  
  284. =item Drivers
  285.  
  286. Users of the DBD modules may read about some of the private functions
  287. and quirks of that driver by typing:
  288.  
  289.     perldoc <driver>
  290.  
  291. For example, the I<DBD::mSQL> driver is bundled with driver-specific
  292. documentation that can be accessed by typing
  293.  
  294.     perldoc DBD::mSQL
  295.  
  296. =item Frequently Asked Questions
  297.  
  298. This document, the I<Frequently Asked Questions> is also available as POD
  299. documentation! You can read this on your own system by typing:
  300.  
  301.     perldoc DBI::FAQ
  302.  
  303. This may be more convenient to persons not permanently, or conveniently,
  304. connected to the Internet. The I<DBI::FAQ> module should be downloaded and
  305. installed for the more up-to-date version.
  306.  
  307. The version of I<DBI::FAQ> shipped with the C<DBI> module may be slightly out
  308. of date.
  309.  
  310. =item POD in general
  311.  
  312. Information on writing POD, and on the philosophy of POD in general, can be
  313. read by typing:
  314.  
  315.     perldoc perlpod
  316.  
  317. Users with the Tk module installed may be interested to learn there is a
  318. Tk-based POD reader available called C<tkpod>, which formats POD in a convenient
  319. and readable way. This is available I<via> CPAN as the module called
  320. I<Tk::POD> and is highly recommended.
  321.  
  322. =back
  323.  
  324. =item I<Driver and Database Characteristics>
  325.  
  326. The driver summaries that were produced for Appendix B of "Programming the
  327. Perl DBI" are available online at:
  328.  
  329.     http://dbi.perl.org/
  330.     http://www.symbolstone.org/technology/perl/DBI
  331.  
  332. in the driver information table. These summaries contain standardised
  333. information on each driver and database which should aid you in selecting
  334. a database to use. It will also inform you quickly of any issues within
  335. drivers or whether a driver is not fully compliant with the DBI Specification.
  336.  
  337. =item I<Rambles, Tidbits and Observations>
  338.  
  339.     http://dbi.perl.org/tidbits
  340.     http://www.symbolstone.org/technology/perl/DBI/tidbits
  341.  
  342. There are a series of occasional rambles from various people on the
  343. DBI mailing lists who, in an attempt to clear up a simple point, end up
  344. drafting fairly comprehensive documents. These are quite often varying in
  345. quality, but do provide some insights into the workings of the interfaces.
  346.  
  347. =item I<Articles>
  348.  
  349. A list of articles discussing the DBI can be found on the DBI WWW page at:
  350.  
  351.     http://dbi.perl.org/
  352.     http://www.symbolstone.org/technology/perl/DBI
  353.  
  354. These articles are of varying quality and age, from the original Perl Journal
  355. article written by Alligator and Tim, to more recent debacles published online
  356. from about.com.
  357.  
  358. =item I<README files>
  359.  
  360. The I<README> files included with each driver occasionally contains
  361. some useful information ( no, really! ) that may be pertinent to the user.
  362. Please read them. It makes our worthless existences more bearable. These
  363. can all be read from the main DBI WWW page at:
  364.  
  365.     http://dbi.perl.org/
  366.     http://www.symbolstone.org/technology/perl/DBI
  367.  
  368. =item I<Mailing Lists>
  369.  
  370. There are three mailing lists for DBI:
  371.  
  372.     dbi-announce@perl.org     -- for announcements, very low traffic
  373.     dbi-users@perl.org        -- general user support
  374.     dbi-dev@perl.org          -- for driver developers (no user support)
  375.  
  376. For information on how to subscribe, set digest mode etc, and unsubscribe,
  377. send an email message (the content will be ignored) to:
  378.  
  379.     dbi-announce-help@perl.org
  380.     dbi-users-help@perl.org
  381.     dbi-dev-help@perl.org
  382.  
  383. =item I<Mailing List Archives>
  384.  
  385. =over 4
  386.  
  387. =item I<US Mailing List Archives>
  388.  
  389.     http://outside.organic.com/mail-archives/dbi-users/
  390.  
  391. Searchable hypermail archives of the three mailing lists, and some of the
  392. much older traffic have been set up for users to browse.
  393.  
  394. =item I<European Mailing List Archives>
  395.  
  396.     http://www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest
  397.  
  398. As per the US archive above.
  399.  
  400. =back
  401.  
  402. =back
  403.  
  404. =head1 Compilation Problems
  405.  
  406. =head2 2.1. Compilation problems or "It fails the test!"
  407.  
  408. First off, consult the README for that driver in case there is useful
  409. information about the problem. It may be a known problem for your given
  410. architecture and operating system or database. You can check the README
  411. files for each driver in advance online at:
  412.  
  413.     http://dbi.perl.org/
  414.     http://www.symbolstone.org/technology/perl/DBI
  415.  
  416. If it's a known problem, you'll probably have to wait till it gets fixed. If
  417. you're I<really> needing it fixed, try the following:
  418.  
  419. =over 4
  420.  
  421. =item I<Attempt to fix it yourself>
  422.  
  423. This technique is generally I<not> recommended to the faint-hearted.
  424. If you do think you have managed to fix it, then, send a patch file
  425. ( context diff ) to the author with an explanation of:
  426.  
  427. =over 4
  428.  
  429. =item *
  430.  
  431. What the problem was, and test cases, if possible.
  432.  
  433. =item *
  434.  
  435. What you needed to do to fix it. Please make sure you mention everything.
  436.  
  437. =item *
  438.  
  439. Platform information, database version, perl version, module version and
  440. DBI version.
  441.  
  442. =back
  443.  
  444. =item I<Email the author> Do I<NOT> whinge!
  445.  
  446. Please email the address listed in the WWW pages for whichever driver you
  447. are having problems with. Do I<not> directly email the author at a
  448. known address unless it corresponds with the one listed.
  449.  
  450. We tend to have real jobs to do, and we do read the mailing lists for
  451. problems. Besides, we may not have access to <I<insert your
  452. favourite brain-damaged platform here>> and couldn't be of any
  453. assistance anyway! Apologies for sounding harsh, but that's the way of it!
  454.  
  455. However, you might catch one of these creative genii at 3am when we're
  456. doing this sort of stuff anyway, and get a patch within 5 minutes. The
  457. atmosphere in the DBI circle is that we I<do> appreciate the users'
  458. problems, since we work in similar environments.
  459.  
  460. If you are planning to email the author, please furnish as much information
  461. as possible, I<ie>:
  462.  
  463. =over 4
  464.  
  465. =item *
  466.  
  467. I<ALL> the information asked for in the README file in
  468. the problematic module. And we mean I<ALL> of it. We don't
  469. put lines like that in documentation for the good of our health, or
  470. to meet obscure README file standards of length.
  471.  
  472. =item *
  473.  
  474. If you have a core dump, try the I<Devel::CoreStack> module for
  475. generating a stack trace from the core dump. Send us that too.
  476. I<Devel::CoreStack> can be found on CPAN at:
  477.  
  478.     http://www.perl.com/cgi-bin/cpan_mod?module=Devel::CoreStack
  479.  
  480. =item *
  481.  
  482. Module versions, perl version, test cases, operating system versions
  483. and I<any other pertinent information>.
  484.  
  485. =back
  486.  
  487. Remember, the more information you send us, the quicker we can track
  488. problems down. If you send us no useful information, expect nothing back.
  489.  
  490. Finally, please be aware that some authors, including Tim Bunce, specifically
  491. request that you do I<not> mail them directly. Please respect their wishes and
  492. use the email addresses listed in the appropriate module C<README> file.
  493.  
  494. =item I<Email the dbi-users Mailing List>
  495.  
  496. It's usually a fairly intelligent idea to I<cc> the mailing list
  497. anyway with problems. The authors all read the lists, so you lose nothing
  498. by mailing there.
  499.  
  500. =back
  501.  
  502. =head1 Platform and Driver Issues
  503.  
  504. =head2 3.1 What's the difference between ODBC and DBI?
  505.  
  506. In terms of architecture - not much: Both define programming
  507. interfaces. Both allow multiple drivers to be loaded to do the
  508. actual work.
  509.  
  510. In terms of ease of use - much: The DBI is a 'high level' interface
  511. that, like Perl itself, strives to make the simple things easy while
  512. still making the hard things possible. The ODBC is a 'low level'
  513. interface. All nuts-bolts-knobs-and-dials.
  514.  
  515. Now there's an ODBC driver for the DBI (DBD::ODBC) the "What's the
  516. difference" question is more usefully rephrased as:
  517.  
  518. Chapter 7 of "Programming the Perl DBI" covers this topic in far more
  519. detail and should be consulted.
  520.  
  521. =head2 3.2 What's the difference between Win32::ODBC and DBD::ODBC?
  522.  
  523. The DBI, and thus DBD::ODBC, has a different philosophy from the
  524. Win32::ODBC module:
  525.  
  526. The Win32::ODBC module is a 'thin' layer over the low-level ODBC API.
  527. The DBI defines a simpler 'higher level' interface.
  528.  
  529. The Win32::ODBC module gives you access to more of the ODBC API.
  530. The DBI and DBD::ODBC give you access to only the essentials.
  531. (But, unlike Win32::ODBC, the DBI and DBD::ODBC do support parameter
  532. binding and multiple prepared statements which reduces the load on
  533. the database server and can dramatically increase performance.)
  534.  
  535. The Win32::ODBC module only works on Win32 systems.
  536. The DBI and DBD::ODBC are very portable and work on Win32 and Unix.
  537.  
  538. The DBI and DBD::ODBC modules are supplied as a standard part of the
  539. Perl 5.004 binary distribution for Win32 (they don't work with the
  540. older, non-standard, ActiveState port).
  541.  
  542. Scripts written with the DBI and DBD::ODBC are faster than Win32::ODBC
  543. on Win32 and are trivially portable to other supported database types.
  544.  
  545. The DBI offers optional automatic printing or die()ing on errors which
  546. makes applications simpler and more robust.
  547.  
  548. The current DBD::ODBC driver version 0.16 is new and not yet fully stable.
  549. A new release is due soon [relative to the date of the next TPJ issue :-]
  550. and will be much improved and offer more ODBC functionality.
  551.  
  552. To summarise: The Win32::ODBC module is your best choice if you need
  553. access to more of the ODBC API than the DBI gives you. Otherwise, the
  554. DBI and DBD::ODBC combination may be your best bet.
  555.  
  556. Chapter 7 of "Programming the Perl DBI" covers this topic in far more
  557. detail and should be consulted.
  558.  
  559. =head2 3.3 Is DBI supported under Windows 95 / NT platforms?
  560.  
  561. Finally, yes! Jeff Urlwin has been working diligently on building
  562. I<DBI> and I<DBD::ODBC> under these platforms, and, with the
  563. advent of a stabler perl and a port of I<MakeMaker>, the project has
  564. come on by great leaps and bounds.
  565.  
  566. The I<DBI> and I<DBD::Oracle> Win32 ports are now a standard part of DBI,
  567. so, downloading I<DBI> of version higher than I<0.81> should work fine as
  568. should using the most recent I<DBD::Oracle> version.
  569.  
  570. =head2 3.4 Can I access Microsoft Access or SQL-Server databases with DBI?
  571.  
  572. Yes, use the I<DBD::ODBC> driver.
  573.  
  574. =head2 3.5 Is the a DBD for <I<insert favourite database here>>?
  575.  
  576. Is is listed on the DBI drivers page?
  577.  
  578.     http://dbi.perl.org/
  579.     http://www.symbolstone.org/technology/perl/DBI
  580.  
  581. If not, no. A complete absence of a given database driver from that
  582. page means that no-one has announced any intention to work on it, not that
  583. such a driver is impossible to write.
  584.  
  585. A corollary of the above statement implies that if you see an announcement
  586. for a driver I<not> on the above page, there's a good chance it's not
  587. actually a I<DBI> driver, and may not conform to the specifications. Therefore,
  588. questions concerning problems with that code should I<not> really be addressed
  589. to the DBI Mailing Lists.
  590.  
  591. =head2 3.6 What's DBM? And why should I use DBI instead?
  592.  
  593. Extracted from ``I<DBI - The Database Interface for Perl 5>'':
  594.  
  595.     ``UNIX was originally blessed with simple file-based ``databases'', namely
  596.     the dbm system. dbm lets you store data in files, and retrieve
  597.     that data quickly. However, it also has serious drawbacks.
  598.  
  599.         File Locking
  600.  
  601.         The dbm systems did not allow particularly robust file locking
  602.         capabilities, nor any capability for correcting problems arising through
  603.         simultaneous writes [ to the database ].
  604.  
  605.         Arbitrary Data Structures
  606.  
  607.         The dbm systems only allows a single fixed data structure:
  608.         key-value pairs. That value could be a complex object, such as a
  609.         [ C ] struct, but the key had to be unique. This was a large
  610.         limitation on the usefulness of dbm systems.
  611.  
  612.     However, dbm systems still provide a useful function for users with
  613.     simple datasets and limited resources, since they are fast, robust and
  614.     extremely well-tested. Perl modules to access dbm systems have now
  615.     been integrated into the core Perl distribution via the
  616.     AnyDBM_File module.''
  617.  
  618. To sum up, DBM is a perfectly satisfactory solution for essentially read-only
  619. databases, or small and simple datasets. However, for more
  620. scaleable dataset handling, not to mention robust transactional locking,
  621. users are recommended to use a more powerful database engine I<via> I<DBI>.
  622.  
  623. Chapter 2 of "Programming the Perl DBI" discusses DBM files in detail.
  624.  
  625. =head2 3.7 What database do you recommend me using?
  626.  
  627. This is a particularly thorny area in which an objective answer is difficult
  628. to come by, since each dataset, proposed usage and system configuration
  629. differs from person to person.
  630.  
  631. From the current author's point of view, if the dataset is relatively
  632. small, being tables of less than 1 million rows, and less than 1000 tables
  633. in a given database, then I<mSQL> is a perfectly acceptable solution
  634. to your problem. This database is extremely cheap, is wonderfully robust
  635. and has excellent support. More information is available on the Hughes
  636. Technology WWW site at:
  637.  
  638.     http://www.hughes.com.au
  639.  
  640. You may also wish to look at MySQL which is a more powerful database engine
  641. that has a similar feel to mSQL.
  642.  
  643.     http://www.tcx.se
  644.  
  645. If the dataset is larger than 1 million row tables or 1000 tables, or if you
  646. have either more money, or larger machines, I would recommend I<Oracle RDBMS>.
  647. Oracle's WWW site is an excellent source of more information.
  648.  
  649.     http://www.oracle.com
  650.  
  651. I<Informix> is another high-end RDBMS that is worth considering. There are
  652. several differences between Oracle and Informix which are too complex for
  653. this document to detail. Information on Informix can be found on their
  654. WWW site at:
  655.  
  656.     http://www.informix.com
  657.  
  658. In the case of WWW fronted applications, I<mSQL> may be a better option
  659. due to slow connection times between a CGI script and the Oracle RDBMS and
  660. also the amount of resource each Oracle connection will consume. I<mSQL>
  661. is lighter resource-wise and faster.
  662.  
  663. These views are not necessarily representative of anyone else's opinions,
  664. and do not reflect any corporate sponsorship or views. They are provided
  665. I<as-is>.
  666.  
  667. =head2 3.8 Is <I<insert feature here>> supported in DBI?
  668.  
  669. Given that we're making the assumption that the feature you have requested
  670. is a non-standard database-specific feature, then the answer will be I<no>.
  671.  
  672. DBI reflects a I<generic> API that will work for most databases, and has
  673. no database-specific functionality.
  674.  
  675. However, driver authors may, if they so desire, include hooks to database-specific
  676. functionality through the C<func()> method defined in the DBI API.
  677. Script developers should note that use of functionality provided I<via>
  678. the C<func()> methods is very unlikely to be portable across databases.
  679.  
  680. =head1 Programming Questions
  681.  
  682. =head2 4.1 Is DBI any use for CGI programming?
  683.  
  684. In a word, yes! DBI is hugely useful for CGI programming! In fact, I would
  685. tentatively say that CGI programming is one of two top uses for DBI.
  686.  
  687. DBI confers the ability to CGI programmers to power WWW-fronted databases
  688. to their users, which provides users with vast quantities of ordered
  689. data to play with. DBI also provides the possibility that, if a site is
  690. receiving far too much traffic than their database server can cope with, they
  691. can upgrade the database server behind the scenes with no alterations to
  692. the CGI scripts.
  693.  
  694. =head2 4.2 How do I get faster connection times with DBD::Oracle and CGI?
  695.  
  696.     Contributed by John D. Groenveld
  697.  
  698. The Apache C<httpd> maintains a pool of C<httpd> children to service client
  699. requests.
  700.  
  701. Using the Apache I<mod_perl> module by I<Doug MacEachern>, the perl
  702. interpreter is embedded with the C<httpd> children. The CGI, DBI, and your
  703. other favorite modules can be loaded at the startup of each child. These
  704. modules will not be reloaded unless changed on disk.
  705.  
  706. For more information on Apache, see the Apache Project's WWW site:
  707.  
  708.     http://www.apache.org
  709.  
  710. The I<mod_perl> module can be downloaded from CPAN I<via>:
  711.  
  712.     http://www.perl.com/cgi-bin/cpan_mod?module=Apache
  713.  
  714. =head2 4.3 How do I get persistent connections with DBI and CGI?
  715.  
  716.     Contributed by John D. Groenveld
  717.  
  718. Using Edmund Mergl's I<Apache::DBI> module, database logins are stored in a
  719. hash with each of these C<httpd> child. If your application is based on a
  720. single database user, this connection can be started with each child.
  721. Currently, database connections cannot be shared between C<httpd> children.
  722.  
  723. I<Apache::DBI> can be downloaded from CPAN I<via>:
  724.  
  725.     http://www.perl.com/cgi-bin/cpan_mod?module=Apache::DBI
  726.  
  727. =head2 4.4 ``When I run a perl script from the command line, it works, but, when I run it under the C<httpd>, it fails!'' Why?
  728.  
  729. Basically, a good chance this is occurring is due to the fact that the user
  730. that you ran it from the command line as has a correctly configured set of
  731. environment variables, in the case of I<DBD::Oracle>, variables like
  732. C<ORACLE_HOME>, C<ORACLE_SID> or C<TWO_TASK>.
  733.  
  734. The C<httpd> process usually runs under the user id of C<nobody>,
  735. which implies there is no configured environment. Any scripts attempting to
  736. execute in this situation will correctly fail.
  737.  
  738. One way to solve this problem is to set the environment for your database in a
  739. C<BEGIN { }> block at the top of your script. Another technique is to configure
  740. your WWW server to pass-through certain environment variables to your CGI
  741. scripts.
  742.  
  743. Similarly, you should check your C<httpd> error logfile for any clues,
  744. as well as the ``Idiot's Guide To Solving Perl / CGI Problems'' and
  745. ``Perl CGI Programming FAQ'' for further information. It is
  746. unlikely the problem is DBI-related.
  747.  
  748. The ``Idiot's Guide To Solving Perl / CGI Problems'' can be located at:
  749.  
  750.     http://www.perl.com/perl/faq/index.html
  751.  
  752. as can the ``Perl CGI Programming FAQ''. Read I<BOTH> these documents
  753. carefully!
  754.  
  755. =head2 4.5 How do I get the number of rows returned from a C<SELECT> statement?
  756.  
  757. Count them. Read the DBI docs for the C<rows()> method.
  758.  
  759. =head1 Miscellaneous Questions
  760.  
  761. =head2 5.1 Can I do multi-threading with DBI?
  762.  
  763. Perl version 5.005 and later can be built to support multi-threading.
  764. The DBI, as of version 1.02, does not yet support multi-threading
  765. so it would be unsafe to let more than one thread enter the DBI at
  766. the same time.
  767.  
  768. It is expected that some future version of the DBI will at least be
  769. thread-safe (but not thread-hot) by automatically blocking threads
  770. intering the DBI while it's already in use.
  771.  
  772. For some OCI example code for Oracle that has multi-threaded C<SELECT>
  773. statements, see:
  774.  
  775.     http://www.symbolstone.org/technology/oracle/oci/orathreads.tar.gz
  776.  
  777. =head2 5.2 How do I handle BLOB data with DBI?
  778.  
  779. Handling BLOB data with the DBI is very straight-forward. BLOB columns are
  780. specified in a SELECT statement as per normal columns. However, you also
  781. need to specify a maximum BLOB size that the <I>database handle</I> can
  782. fetch using the C<LongReadLen> attribute.
  783.  
  784. For example:
  785.  
  786.     ### $dbh is a connected database handle
  787.     $sth = $dbh->prepare( "SELECT blob_column FROM blobby_table" );
  788.     $sth->execute;
  789.  
  790. would fail.
  791.  
  792.     ### $dbh is a connected database handle
  793.     ### Set the maximum BLOB size...
  794.     $dbh->{LongReadLen} = 16384;        ### 16Kb...Not much of a BLOB!
  795.  
  796.     $sth = $dbh->prepare( "..." );
  797.  
  798. would succeed <I>provided no column values were larger than the specified
  799. value</I>.
  800.  
  801. If the BLOB data is longer than the value of C<LongReadLen>, then an
  802. error will occur. However, the DBI provides an additional piece of
  803. functionality that will automatically truncate the fetched BLOB to the
  804. size of C<LongReadLen> if it is longer. This does not cause an error to
  805. occur, but may make your fetched BLOB data useless.
  806.  
  807. This behaviour is regulated by the C<LongTruncOk> attribute which is
  808. defaultly set to a false value ( thus making overlong BLOB fetches fail ).
  809.  
  810.     ### Set BLOB handling such that it's 16Kb and can be truncated
  811.     $dbh->{LongReadLen} = 16384;
  812.     $dbh->{LongTruncOk} = 1;
  813.  
  814. Truncation of BLOB data may not be a big deal in cases where the BLOB
  815. contains run-length encoded data, but data containing checksums at the end,
  816. for example, a ZIP file, would be rendered useless.
  817.  
  818. =head2 5.3 How can I invoke stored procedures with DBI?
  819.  
  820. The DBI does not define a database-independent way of calling stored procedures.
  821.  
  822. However, most database that support them also provide a way to call
  823. them from SQL statements - and the DBI certainly supports that.
  824.  
  825. So, assuming that you have created a stored procedure within the target
  826. database, I<eg>, an Oracle database, you can use C<$dbh>->C<do()> to
  827. immediately execute the procedure. For example,
  828.  
  829.     $dbh->do( "BEGIN someProcedure; END;" );   # Oracle-specific
  830.  
  831. You should also be able to C<prepare> and C<execute>, which is
  832. the recommended way if you'll be calling the procedure often.
  833.  
  834. =head2 5.4 How can I get return values from stored procedures with DBI?
  835.  
  836.     Contributed by Jeff Urlwin
  837.  
  838.     $sth = $dbh->prepare( "BEGIN foo(:1, :2, :3); END;" );
  839.     $sth->bind_param(1, $a);
  840.     $sth->bind_param_inout(2, \$path, 2000);
  841.     $sth->bind_param_inout(3, \$success, 2000);
  842.     $sth->execute;
  843.  
  844. Remember to perform error checking, though! ( Or use the C<RaiseError>
  845. attribute ).
  846.  
  847. =head2 5.5 How can I create or drop a database with DBI?
  848.  
  849. Database creation and deletion are concepts that are entirely too abstract
  850. to be adequately supported by DBI. For example, Oracle does not support the
  851. concept of dropping a database at all! Also, in Oracle, the database
  852. I<server> essentially I<is> the database, whereas in mSQL, the
  853. server process runs happily without any databases created in it. The
  854. problem is too disparate to attack in a worthwhile way.
  855.  
  856. Some drivers, therefore, support database creation and deletion through
  857. the private C<func()> methods. You should check the documentation for
  858. the drivers you are using to see if they support this mechanism.
  859.  
  860. =head2 5.6 How can I C<commit> or C<rollback> a statement with DBI?
  861.  
  862. See the C<commit()> and C<rollback()> methods in the DBI Specification.
  863.  
  864. Chapter 6 of "Programming the Perl DBI" discusses transaction handling within
  865. the context of DBI in more detail.
  866.  
  867. =head2 5.7 How are C<NULL> values handled by DBI?
  868.  
  869. C<NULL> values in DBI are specified to be treated as the value C<undef>.
  870. C<NULL>s can be inserted into databases as C<NULL>, for example:
  871.  
  872.     $rv = $dbh->do( "INSERT INTO table VALUES( NULL )" );
  873.  
  874. but when queried back, the C<NULL>s should be tested against C<undef>.
  875. This is standard across all drivers.
  876.  
  877. =head2 5.8 What are these C<func()> methods all about?
  878.  
  879. The C<func()> method is defined within DBI as being an entry point
  880. for database-specific functionality, I<eg>, the ability to create or
  881. drop databases. Invoking these driver-specific methods is simple, for example,
  882. to invoke a C<createDatabase> method that has one argument, we would
  883. write:
  884.  
  885.     $rv =$dbh->func( 'argument', 'createDatabase' );
  886.  
  887. Software developers should note that the C<func()> methods are
  888. non-portable between databases.
  889.  
  890. =head2 5.9 Is DBI Year 2000 Compliant?
  891.  
  892. DBI has no knowledge of understanding of what dates are. Therefore, DBI
  893. itself does not have a Year 2000 problem. Individual drivers may use date
  894. handling code internally and therefore be potentially susceptible to the
  895. Year 2000 problem, but this is unlikely.
  896.  
  897. You may also wish to read the ``Does Perl have a Year 2000 problem?'' section
  898. of the Perl FAQ at:
  899.  
  900.     http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html
  901.  
  902. =head1 Support and Training
  903.  
  904. The Perl5 Database Interface is I<FREE> software. IT COMES WITHOUT WARRANTY
  905. OF ANY KIND. See the DBI README for more details.
  906.  
  907. However, some organizations are providing either technical support or
  908. training programs on DBI. The present author has no knowledge as
  909. to the quality of these services. The links are included for reference
  910. purposes only and should not be regarded as recommendations in any way.
  911. I<Caveat emptor>.
  912.  
  913. =head2 Commercial Support
  914.  
  915. =over 4
  916.  
  917. =item The Perl Clinic
  918.  
  919. The Perl Clinic provides commercial support for I<Perl> and Perl
  920. related problems, including the I<DBI> and its drivers.  Support is
  921. provided by the company with whom Tim Bunce, author of I<DBI> and
  922. I<DBD::Oracle>, works and ActiveState. For more information on their
  923. services, please see:
  924.  
  925.     http://www.perlclinic.com
  926.  
  927. =back
  928.  
  929. =head2 Training
  930.  
  931. =over 4
  932.  
  933. =item Westlake Solutions
  934.  
  935. A hands-on class for experienced Perl CGI developers that teaches
  936. how to write database-connected CGI scripts using Perl and DBI.pm.  This
  937. course, along with four other courses on CGI scripting with Perl, is
  938. taught in Washington, DC; Arlington, Virginia; and on-site worldwide upon
  939. request.
  940.  
  941. See:
  942.  
  943.     http://www.westlake.com/training
  944.  
  945. for more details.
  946.  
  947. =back
  948.  
  949. =head1 Other References
  950.  
  951. In this section, we present some miscellaneous WWW links that may be of
  952. some interest to DBI users. These are not verified and may result in
  953. unknown sites or missing documents.
  954.  
  955.     http://www-ccs.cs.umass.edu/db.html
  956.     http://www.odmg.org/odmg93/updates_dbarry.html
  957.     http://www.jcc.com/sql_stnd.html
  958.  
  959. =head1 AUTHOR
  960.  
  961. Alligator Descartes <I<http://www.symbolstone.org/descarte/contact.html>>.
  962. Portions are Copyright their original stated authors.
  963.  
  964. =head1 COPYRIGHT
  965.  
  966. This document is Copyright (c)1994-2000 Alligator Descartes, with portions
  967. Copyright (c)1994-2000 their original authors. This module is released under
  968. the 'Artistic' license which you can find in the perl distribution.
  969.  
  970. This document is Copyright (c)1997-2000 Alligator Descartes. All rights reserved.
  971. Permission to distribute this document, in full or in part, via email,
  972. Usenet, ftp archives or http is granted providing that no charges are involved,
  973. reasonable attempt is made to use the most current version and all credits
  974. and copyright notices are retained ( the I<AUTHOR> and I<COPYRIGHT> sections ).
  975. Requests for other distribution rights, including incorporation into
  976. commercial products, such as books, magazine articles or CD-ROMs should be
  977. made to Alligator Descartes <I<http://www.symbolstone.org/descarte/contact.html>>.
  978.  
  979. =for html
  980. <!--#include virtual="/technology/perl/DBI/templatebottom.html" -->
  981. </BODY>
  982. </HTML>
  983.