📄 dbi::faq.3
字号:
.Vb 1\& http://www.hughes.com.au.Ve.PPYou may also wish to look at MySQL which is a more powerful database enginethat has a similar feel to mSQL..PP.Vb 1\& http://www.tcx.se.Ve.PPIf the dataset is larger than 1 million row tables or 1000 tables, or if youhave either more money, or larger machines, I would recommend \fIOracle \s-1RDBMS\s0\fR.Oracle's \s-1WWW\s0 site is an excellent source of more information..PP.Vb 1\& http://www.oracle.com.Ve.PP\&\fIInformix\fR is another high-end \s-1RDBMS\s0 that is worth considering. There areseveral differences between Oracle and Informix which are too complex forthis document to detail. Information on Informix can be found on their\&\s-1WWW\s0 site at:.PP.Vb 1\& http://www.informix.com.Ve.PPIn the case of \s-1WWW\s0 fronted applications, \fImSQL\fR may be a better optiondue to slow connection times between a \s-1CGI\s0 script and the Oracle \s-1RDBMS\s0 andalso the amount of resource each Oracle connection will consume. \fImSQL\fRis lighter resource-wise and faster..PPThese views are not necessarily representative of anyone else's opinions,and do not reflect any corporate sponsorship or views. They are provided\&\fIas-is\fR..Sh "3.8 Is <\fIinsert feature here\fP> supported in \s-1DBI\s0?".IX Subsection "3.8 Is <insert feature here> supported in DBI?"Given that we're making the assumption that the feature you have requestedis a non-standard database-specific feature, then the answer will be \fIno\fR..PP\&\s-1DBI\s0 reflects a \fIgeneric\fR \s-1API\s0 that will work for most databases, and hasno database-specific functionality..PPHowever, driver authors may, if they so desire, include hooks to database-specificfunctionality through the \f(CW\*(C`func()\*(C'\fR method defined in the \s-1DBI\s0 \s-1API\s0.Script developers should note that use of functionality provided \fIvia\fRthe \f(CW\*(C`func()\*(C'\fR methods is very unlikely to be portable across databases..SH "Programming Questions".IX Header "Programming Questions".Sh "4.1 Is \s-1DBI\s0 any use for \s-1CGI\s0 programming?".IX Subsection "4.1 Is DBI any use for CGI programming?"In a word, yes! \s-1DBI\s0 is hugely useful for \s-1CGI\s0 programming! In fact, I wouldtentatively say that \s-1CGI\s0 programming is one of two top uses for \s-1DBI\s0..PP\&\s-1DBI\s0 confers the ability to \s-1CGI\s0 programmers to power WWW-fronted databasesto their users, which provides users with vast quantities of ordereddata to play with. \s-1DBI\s0 also provides the possibility that, if a site isreceiving far too much traffic than their database server can cope with, theycan upgrade the database server behind the scenes with no alterations tothe \s-1CGI\s0 scripts..Sh "4.2 How do I get faster connection times with DBD::Oracle and \s-1CGI\s0?".IX Subsection "4.2 How do I get faster connection times with DBD::Oracle and CGI?".Vb 1\& Contributed by John D. Groenveld.Ve.PPThe Apache \f(CW\*(C`httpd\*(C'\fR maintains a pool of \f(CW\*(C`httpd\*(C'\fR children to service client requests..PPUsing the Apache \fImod_perl\fR module by \fIDoug MacEachern\fR, the perl interpreter is embedded with the \f(CW\*(C`httpd\*(C'\fR children. The \s-1CGI\s0, \s-1DBI\s0, and your other favorite modules can be loaded at the startup of each child. These modules will not be reloaded unless changed on disk..PPFor more information on Apache, see the Apache Project's \s-1WWW\s0 site:.PP.Vb 1\& http://www.apache.org.Ve.PPThe \fImod_perl\fR module can be downloaded from \s-1CPAN\s0 \fIvia\fR:.PP.Vb 1\& http://www.perl.com/cgi\-bin/cpan_mod?module=Apache.Ve.Sh "4.3 How do I get persistent connections with \s-1DBI\s0 and \s-1CGI\s0?".IX Subsection "4.3 How do I get persistent connections with DBI and CGI?".Vb 1\& Contributed by John D. Groenveld.Ve.PPUsing Edmund Mergl's \fIApache::DBI\fR module, database logins are stored in a hash with each of these \f(CW\*(C`httpd\*(C'\fR 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 \f(CW\*(C`httpd\*(C'\fR children..PP\&\fIApache::DBI\fR can be downloaded from \s-1CPAN\s0 \fIvia\fR:.PP.Vb 1\& http://www.perl.com/cgi\-bin/cpan_mod?module=Apache::DBI.Ve.ie n .Sh "4.4 ``When I run a perl script from the command line, it works, but, when I run it under the ""httpd"", it fails!'' Why?".el .Sh "4.4 ``When I run a perl script from the command line, it works, but, when I run it under the \f(CWhttpd\fP, it fails!'' Why?".IX Subsection "4.4 ``When I run a perl script from the command line, it works, but, when I run it under the httpd, it fails!'' Why?"Basically, a good chance this is occurring is due to the fact that the userthat you ran it from the command line as has a correctly configured set ofenvironment variables, in the case of \fIDBD::Oracle\fR, variables like\&\f(CW\*(C`ORACLE_HOME\*(C'\fR, \f(CW\*(C`ORACLE_SID\*(C'\fR or \f(CW\*(C`TWO_TASK\*(C'\fR..PPThe \f(CW\*(C`httpd\*(C'\fR process usually runs under the user id of \f(CW\*(C`nobody\*(C'\fR,which implies there is no configured environment. Any scripts attempting toexecute in this situation will correctly fail..PPOne way to solve this problem is to set the environment for your database in a\&\f(CW\*(C`BEGIN { }\*(C'\fR block at the top of your script. Another technique is to configureyour \s-1WWW\s0 server to pass-through certain environment variables to your \s-1CGI\s0 scripts..PPSimilarly, you should check your \f(CW\*(C`httpd\*(C'\fR error logfile for any clues,as well as the ``Idiot's Guide To Solving Perl / \s-1CGI\s0 Problems'' and``Perl \s-1CGI\s0 Programming \s-1FAQ\s0'' for further information. It isunlikely the problem is DBI-related..PPThe ``Idiot's Guide To Solving Perl / \s-1CGI\s0 Problems'' can be located at:.PP.Vb 1\& http://www.perl.com/perl/faq/index.html.Ve.PPas can the ``Perl \s-1CGI\s0 Programming \s-1FAQ\s0''. Read \fI\s-1BOTH\s0\fR these documents carefully!.ie n .Sh "4.5 How do I get the number of rows returned from a ""SELECT"" statement?".el .Sh "4.5 How do I get the number of rows returned from a \f(CWSELECT\fP statement?".IX Subsection "4.5 How do I get the number of rows returned from a SELECT statement?"Count them. Read the \s-1DBI\s0 docs for the \f(CW\*(C`rows()\*(C'\fR method..SH "Miscellaneous Questions".IX Header "Miscellaneous Questions".Sh "5.1 Can I do multi-threading with \s-1DBI\s0?".IX Subsection "5.1 Can I do multi-threading with DBI?"Perl version 5.005 and later can be built to support multi-threading.The \s-1DBI\s0, as of version 1.02, does not yet support multi-threadingso it would be unsafe to let more than one thread enter the \s-1DBI\s0 atthe same time..PPIt is expected that some future version of the \s-1DBI\s0 will at least bethread-safe (but not thread-hot) by automatically blocking threadsintering the \s-1DBI\s0 while it's already in use..PPFor some \s-1OCI\s0 example code for Oracle that has multi-threaded \f(CW\*(C`SELECT\*(C'\fRstatements, see:.PP.Vb 1\& http://www.symbolstone.org/technology/oracle/oci/orathreads.tar.gz.Ve.Sh "5.2 How do I handle \s-1BLOB\s0 data with \s-1DBI\s0?".IX Subsection "5.2 How do I handle BLOB data with DBI?"Handling \s-1BLOB\s0 data with the \s-1DBI\s0 is very straight-forward. \s-1BLOB\s0 columns arespecified in a \s-1SELECT\s0 statement as per normal columns. However, you alsoneed to specify a maximum \s-1BLOB\s0 size that the <I>database handle</I> canfetch using the \f(CW\*(C`LongReadLen\*(C'\fR attribute..PPFor example:.PP.Vb 3\& ### $dbh is a connected database handle\& $sth = $dbh\->prepare( "SELECT blob_column FROM blobby_table" );\& $sth\->execute;.Ve.PPwould fail..PP.Vb 3\& ### $dbh is a connected database handle\& ### Set the maximum BLOB size...\& $dbh\->{LongReadLen} = 16384; ### 16Kb...Not much of a BLOB!\&\& $sth = $dbh\->prepare( "..." );.Ve.PPwould succeed <I>provided no column values were larger than the specifiedvalue</I>..PPIf the \s-1BLOB\s0 data is longer than the value of \f(CW\*(C`LongReadLen\*(C'\fR, then anerror will occur. However, the \s-1DBI\s0 provides an additional piece offunctionality that will automatically truncate the fetched \s-1BLOB\s0 to thesize of \f(CW\*(C`LongReadLen\*(C'\fR if it is longer. This does not cause an error tooccur, but may make your fetched \s-1BLOB\s0 data useless..PPThis behaviour is regulated by the \f(CW\*(C`LongTruncOk\*(C'\fR attribute which is defaultly set to a false value ( thus making overlong \s-1BLOB\s0 fetches fail )..PP.Vb 3\& ### Set BLOB handling such that it\*(Aqs 16Kb and can be truncated\& $dbh\->{LongReadLen} = 16384;\& $dbh\->{LongTruncOk} = 1;.Ve.PPTruncation of \s-1BLOB\s0 data may not be a big deal in cases where the \s-1BLOB\s0contains run-length encoded data, but data containing checksums at the end,for example, a \s-1ZIP\s0 file, would be rendered useless..Sh "5.3 How can I invoke stored procedures with \s-1DBI\s0?".IX Subsection "5.3 How can I invoke stored procedures with DBI?"The \s-1DBI\s0 does not define a database-independent way of calling stored procedures..PPHowever, most database that support them also provide a way to callthem from \s-1SQL\s0 statements \- and the \s-1DBI\s0 certainly supports that..PPSo, assuming that you have created a stored procedure within the targetdatabase, \fIeg\fR, an Oracle database, you can use \f(CW$dbh\fR\->\f(CW\*(C`do()\*(C'\fR toimmediately execute the procedure. For example,.PP.Vb 1\& $dbh\->do( "BEGIN someProcedure; END;" ); # Oracle\-specific.Ve.PPYou should also be able to \f(CW\*(C`prepare\*(C'\fR and \f(CW\*(C`execute\*(C'\fR, which isthe recommended way if you'll be calling the procedure often..Sh "5.4 How can I get return values from stored procedures with \s-1DBI\s0?".IX Subsection "5.4 How can I get return values from stored procedures with DBI?".Vb 1\& Contributed by Jeff Urlwin\&\& $sth = $dbh\->prepare( "BEGIN foo(:1, :2, :3); END;" );\& $sth\->bind_param(1, $a);\& $sth\->bind_param_inout(2, \e$path, 2000);\& $sth\->bind_param_inout(3, \e$success, 2000);\& $sth\->execute;.Ve.PPRemember to perform error checking, though! ( Or use the \f(CW\*(C`RaiseError\*(C'\fRattribute )..Sh "5.5 How can I create or drop a database with \s-1DBI\s0?".IX Subsection "5.5 How can I create or drop a database with DBI?"Database creation and deletion are concepts that are entirely too abstractto be adequately supported by \s-1DBI\s0. For example, Oracle does not support theconcept of dropping a database at all! Also, in Oracle, the database\&\fIserver\fR essentially \fIis\fR the database, whereas in mSQL, theserver process runs happily without any databases created in it. Theproblem is too disparate to attack in a worthwhile way..PPSome drivers, therefore, support database creation and deletion throughthe private \f(CW\*(C`func()\*(C'\fR methods. You should check the documentation forthe drivers you are using to see if they support this mechanism..ie n .Sh "5.6 How can I ""commit""\fP or \f(CW""rollback"" a statement with \s-1DBI\s0?".el .Sh "5.6 How can I \f(CWcommit\fP or \f(CWrollback\fP a statement with \s-1DBI\s0?".IX Subsection "5.6 How can I commit or rollback a statement with DBI?"See the \f(CW\*(C`commit()\*(C'\fR and \f(CW\*(C`rollback()\*(C'\fR methods in the \s-1DBI\s0 Specification..PPChapter 6 of \*(L"Programming the Perl \s-1DBI\s0\*(R" discusses transaction handling withinthe context of \s-1DBI\s0 in more detail..ie n .Sh "5.7 How are ""NULL"" values handled by \s-1DBI\s0?".el .Sh "5.7 How are \f(CWNULL\fP values handled by \s-1DBI\s0?".IX Subsection "5.7 How are NULL values handled by DBI?"\&\f(CW\*(C`NULL\*(C'\fR values in \s-1DBI\s0 are specified to be treated as the value \f(CW\*(C`undef\*(C'\fR.\&\f(CW\*(C`NULL\*(C'\fRs can be inserted into databases as \f(CW\*(C`NULL\*(C'\fR, for example:.PP.Vb 1\& $rv = $dbh\->do( "INSERT INTO table VALUES( NULL )" );.Ve.PPbut when queried back, the \f(CW\*(C`NULL\*(C'\fRs should be tested against \f(CW\*(C`undef\*(C'\fR.This is standard across all drivers..ie n .Sh "5.8 What are these ""func()"" methods all about?".el .Sh "5.8 What are these \f(CWfunc()\fP methods all about?".IX Subsection "5.8 What are these func() methods all about?"The \f(CW\*(C`func()\*(C'\fR method is defined within \s-1DBI\s0 as being an entry pointfor database-specific functionality, \fIeg\fR, the ability to create ordrop databases. Invoking these driver-specific methods is simple, for example,to invoke a \f(CW\*(C`createDatabase\*(C'\fR method that has one argument, we wouldwrite:.PP.Vb 1\& $rv =$dbh\->func( \*(Aqargument\*(Aq, \*(AqcreateDatabase\*(Aq );.Ve.PPSoftware developers should note that the \f(CW\*(C`func()\*(C'\fR methods arenon-portable between databases..Sh "5.9 Is \s-1DBI\s0 Year 2000 Compliant?".IX Subsection "5.9 Is DBI Year 2000 Compliant?"\&\s-1DBI\s0 has no knowledge of understanding of what dates are. Therefore, \s-1DBI\s0itself does not have a Year 2000 problem. Individual drivers may use datehandling code internally and therefore be potentially susceptible to theYear 2000 problem, but this is unlikely..PPYou may also wish to read the ``Does Perl have a Year 2000 problem?'' sectionof the Perl \s-1FAQ\s0 at:.PP.Vb 1\& http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html.Ve.SH "Support and Training".IX Header "Support and Training"The Perl5 Database Interface is \fI\s-1FREE\s0\fR software. \s-1IT\s0 \s-1COMES\s0 \s-1WITHOUT\s0 \s-1WARRANTY\s0\&\s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0. See the \s-1DBI\s0 \s-1README\s0 for more details..PPHowever, some organizations are providing either technical support ortraining programs on \s-1DBI\s0. The present author has no knowledge asto the quality of these services. The links are included for referencepurposes only and should not be regarded as recommendations in any way.\&\fICaveat emptor\fR..Sh "Commercial Support".IX Subsection "Commercial Support".IP "The Perl Clinic" 4.IX Item "The Perl Clinic"The Perl Clinic provides commercial support for \fIPerl\fR and Perlrelated problems, including the \fI\s-1DBI\s0\fR and its drivers. Support isprovided by the company with whom Tim Bunce, author of \fI\s-1DBI\s0\fR and\&\fIDBD::Oracle\fR, works and ActiveState. For more information on theirservices, please see:.Sp.Vb 1\& http://www.perlclinic.com.Ve.Sh "Training".IX Subsection "Training".IP "Westlake Solutions" 4.IX Item "Westlake Solutions"A hands-on class for experienced Perl \s-1CGI\s0 developers that teacheshow to write database-connected \s-1CGI\s0 scripts using Perl and \s-1DBI\s0.pm. Thiscourse, along with four other courses on \s-1CGI\s0 scripting with Perl, istaught in Washington, \s-1DC\s0; Arlington, Virginia; and on-site worldwide uponrequest..SpSee:.Sp.Vb 1\& http://www.westlake.com/training.Ve.Spfor more details..SH "Other References".IX Header "Other References"In this section, we present some miscellaneous \s-1WWW\s0 links that may be ofsome interest to \s-1DBI\s0 users. These are not verified and may result inunknown sites or missing documents..PP.Vb 3\& http://www\-ccs.cs.umass.edu/db.html\& http://www.odmg.org/odmg93/updates_dbarry.html\& http://www.jcc.com/sql_stnd.html.Ve.SH "AUTHOR".IX Header "AUTHOR"Alligator Descartes <\fIhttp://www.symbolstone.org/descarte/contact.html\fR>. Portions are Copyright their original stated authors..SH "COPYRIGHT".IX Header "COPYRIGHT"This document is Copyright (c)1994\-2000 Alligator Descartes, with portionsCopyright (c)1994\-2000 their original authors. This module is released underthe 'Artistic' license which you can find in the perl distribution..PPThis document is Copyright (c)1997\-2000 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 creditsand copyright notices are retained ( the \fI\s-1AUTHOR\s0\fR and \fI\s-1COPYRIGHT\s0\fR sections ).Requests for other distribution rights, including incorporation into commercial products, such as books, magazine articles or CD-ROMs should bemade to Alligator Descartes <\fIhttp://www.symbolstone.org/descarte/contact.html\fR>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -