⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch08.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
23:  $fstring = $query->param(`string');



24:  if ( $fstring ) {



25:    $fstring = &prep_regex ($fstring);



26:    $where_string = $where_string . $conjunc .



27:      "title LIKE $fstring OR subtitle LIKE $fstring OR narrative LIKE $fstring";



28:    $conjunc = " AND ";



29:  }



30:  $fmedium = $query->param(`medium');



31:  if ( $fmedium && $fmedium ne `Any' ) {



32:    $where_string = $where_string . $conjunc . "type = `$fmedium'";



33:    $conjunc = " AND ";



34:  }



35:  $fpuber = $query->param(`puber');



36:  if ( $fpuber ) {



37:    $fpuber = &prep_regex ($fpuber);



38:    $where_string = $where_string . $conjunc . "publisher LIKE $fpuber";



39:    $conjunc = " AND ";



40:  }



41:  $faud = $query->param(`aud');



42:  if ( $faud && $faud ne `Any' ) {



43:    $where_string = $where_string . $conjunc . " $faud <> NULL";



44:    $conjunc = " AND ";



45:  }











46:  if ( $where_string ) {



47:    $hit_limit = $query->param(`hitlimit') || "25";



48:    &pheader;



49:    &search;



50:    &ptrailer;



51:  } else {



52:    &pheader;



53:    &ptrailer;



54:  }



55:  exit;











56:  #prepare a search string for use in mSQL LIKE



57:  sub prep_regex {



58:    $_[0] =~ s/\[/\[\[\]/g;



59:    $_[0] =~ s/\\/\[\\\\\\\\\]/g;           # no good - backslash breaks LIKE



60:    $_[0] =~ s/([\$%\(\)\?\^|])/\[$1\]/g;



61:    $_[0] =~ s/\'/\\\'/g;



62:    $_[0] =~ s/_/\\\\_/g;



63:    $_[0] =~ s/([A-Za-z])/\[\l$1\u$1\]/g;



64:    return "`%" . $_[0] . "%'";



65:  }











66:  #search the database



67:  sub search {



68:    use DBI;



69:    $drh = DBI->install_driver( `mSQL' )



70:            || die "Could not install: $DBI::errstr";



71:    $dbh = $drh->connect( ``, `AV_LIBRARY' )



72:            || die "Could not connect: $DBI::errstr";



73:    $sth = $dbh->prepare( "SELECT call_num, title, subtitle FROM catalog



74:                           $where_string LIMIT $hit_limit" )



75:            || die "Could not start select: $DBI::errstr";



76:    $sth->execute || die "Could not select: $DBI::errstr";



77:    print "<b>Search Results</b>\n<ol>\n ";



78:    while ( ($call_num, $title, $subtitle) = $sth->fetchrow ) {



79:      print qq!  <li><tt><a href="display.cgi?cn=$call_num">$call_num</a></tt>



80:               $title\n!;



81:      if ( $subtitle ) {



82:        print " $subtitle\n";



83:      }



84:      $hits++;



85:    }



86:    print "</ol>\n";



87:    if ( ! $hits ) {



88:      print "<b>No</b> matches\n";



89:    } elsif ( $hits >= $hit_limit ) {



90:      print "Search stopped after first <b>$hits</b> matches.\n";



91:    }



92:    $sth->finish || die "Could not finish select: $DBI::errstr";



93:  }











94:  #send the header



95:  sub pheader {



96:    print $query->header;



97:    print <<EOD;



98:  <HTML>







99:  <HEAD>



100:   <TITLE>MCES's Audiovisual Reference Room - Search</TITLE>



101:    <LINK REV="MADE" HREF="mailto:avlibrar\@ces.msstate.edu">



102:    <META NAME="MarkUp" CONTENT="Tom White">



103:  </HEAD>







104:  <BODY>







105:  <h1><img src="/pics/ces-b1mt.gif" width=499 height=53



106:           alt="Cooperative Extension Service -



107:               Mississippi State University">



108: </h1>







109: <h2>



110:   Audiovisual Reference Room



111: </h2>







112: <h3>



113:   Search



114: </h3>







115: EOD



116: print $query->startform(`GET', `search.cgi', `""`);



117: print "<b>String:</b> ";



118: print $query->textfield(-name=>`string', -default=>``, -size=>15,



119:                         -maxlength=>30);



120: print "    (Must appear in either title or narrative.)\n";



121: print "<br><b>Medium:</b> ";



122: print $query->popup_menu(-name=>`medium', -default=>`Any',



123:                          -values=>[`Any','Film','Slide','Audio','Video']);



124: print "\n<br><b>Publisher:</b> ";



125: print $query->textfield(-name=>`puber', -default=>``, -size=>15,



126:                         -maxlength=>15);



127: print "    (Must appear under Publisher.)\n";



128: print "<br><b>Audience:</b> ";



129: print $query->popup_menu(-name=>`aud', -default=>`Any',



130:       -values=>[`Any','kinder','primer','element','junior',



131:                 `senior','college','adult'],



132:       -labels=>{`Any'=>,'Any',



133:                 `kinder'=>,'Kindergarten (ages 3-5)',



134:                 `primer'=>,'Primary (grades 1-3)',



135:                 `element'=>,'Elementary (grades 4-6)',



136:                 `junior'=>,'Junior High (grades 7-9)',



137:                 `senior'=>,'Senior High (grades 10-12)',



138:                 `college'=>,'College',



139:                 `adult'=>`Adult'});



140: print "\n<br>\n";



141: print $query->submit(`Start Search'), "\n";



142: print "Stop search after ";



143: print $query->popup_menu(-name=>`hitlimit', -default=>`25',



144:                          -values=>[`10','25','50','100','9999']);



145: print " matches\n";



146: print $query->endform, "\n";



147: }















148: #send the trailer



149: sub ptrailer {



150:   print <<EOD;







151: <HR>



152:   [<a href="./">Audiovisual Reference Room</a>]



153:   <br>



154:   [<a href="/ces.html">Cooperative Extension</a>]



155:   [<a href="http://www.msstate.edu/">Mississippi State</a>]



156:   [<a href="http://www.msstate.edu/web/search.htm">Search MSU's Web</a>]



157:   <br>



158:   <FONT SIZE="-1">



159:   For information about this page, contact



160:      <a href="mailto:avlibrar\@ces.msstate.edu">avlibrar\@ces.msstate.edu</a>.



161:   <br>



162:   <b>Last modified:</b> 08-06-96



163:   <br>



164:   <A HREF="http://www.msstate.edu/web/disclaim.htm">Mississippi State University 



       is an equal opportunity institution.</A>



165:   </FONT>







166: </BODY>







167: </HTML>



168: EOD



</FONT></PRE>



<PRE><FONT COLOR="#0066FF">169: }</FONT></PRE>



<P><A HREF="09wpp03.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/09wpp03.jpg"><TT><B>Figure 8.3.</B></TT></A> Output from



Listing 8.5.</P>



<P><A HREF="09wpp04.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/09wpp04.jpg"><TT><B>Figure 8.4.</B></TT></A> More output



from Listing 8.5.



<CENTER>



<H3><A NAME="Heading19"></A><FONT COLOR="#000077">Open Database Connectivity (ODBC)</FONT></H3>



</CENTER>



<P>Microsoft's Open Database Connectivity API attempts to define a standard SQL syntax



common to all database engines. The standard is based on the SQL-Access group's CLI,



which has been adopted as an international standard. Microsoft has developed a call-level



interface based directly on the SQL CLI. ODBC will make the development of generic,



scalable client applications such as CGI/Perl5 interfaces less difficult once drivers



and interfaces are more universally available.</P>



<P>ODBC is a component of Microsoft's Windows Open Services Architecture (WOSA).



Applications can call a generic API, which is routed to the appropriate database-specific



driver.</P>



<P>Database vendors are currently adopting ODBC as the native CLI for their database



engines. ODBC drivers are currently being included in most commercial database packages.



An ODBC driver manager is included in current releases of Sun's Solaris OS. ODBC



is quickly becoming the standard. ODBC does not replace DBI, however. Currently,



DBI's DBM modules provide access to the differing proprietary APIs implemented by



the different database vendors. The DBI module itself provides a Perl5 object oriented



interface to the database through the DBM modules. A Perl interface is still necessary



to the ODBC API. Tim Bruce, the author of DBI, is currently rewriting DBI to fully



support ODBC. The new DBI will include a new low-level ODBC API interface, along



with high-level methods similar to the current DBI interface. The latest information



on the development of DBI can be found at</P>



<PRE><A HREF="javascript:if(confirm('http://www.hermetica.com/technologia/DBI/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.hermetica.com/technologia/DBI/'" tppabs="http://www.hermetica.com/technologia/DBI/"><FONT COLOR="#0066FF">http://www.hermetica.com/technologia/DBI/



</FONT></A><FONT COLOR="#0066FF"></FONT></PRE>



<P>There is currently a Perl5 ODBC module for the 32-bit Windows architectures, including



Windows 95 and Windows NT for Intel and DEC Alpha. The module is currently being



ported to Macintosh and various flavors of UNIX and should be available on these



platforms by the time you read this. The module is called Win32::ODBC and is being



written by Dave Roth. Dave's Win32 ODBC.pm module is based on the original ODBC.PM



code written by Dan DeMaggio.</P>



<P>Win32::ODBC may be obtained from the following URL:</P>



<PRE><A HREF="javascript:if(confirm('http://www.perl.com/CPAN/authors/Dave_Roth/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.perl.com/CPAN/authors/Dave_Roth/'" tppabs="http://www.perl.com/CPAN/authors/Dave_Roth/"><FONT COLOR="#0066FF">http://www.perl.com/CPAN/authors/Dave_Roth/</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<P>Currently, in order to use this module, you must be running on some 32-bit Windows



architecture such as NT 3.51, 4.0, or Windows 95. You must install version 3.0 or



greater of Microsoft's ODBC interface drivers and have Win32 Perl installed and working.



The latest version of the ODBC drivers can be obtained directly from Microsoft at



the following URL:</P>



<PRE><A HREF="javascript:if(confirm('http://www.microsoft.com/kb/softlib/mslfiles/WX1220.EXE  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.microsoft.com/kb/softlib/mslfiles/WX1220.EXE'" tppabs="http://www.microsoft.com/kb/softlib/mslfiles/WX1220.EXE"><FONT COLOR="#0066FF">http://www.microsoft.com/kb/softlib/mslfiles/WX1220.EXE</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<P>Win32::ODBC is currently not compatible with the DBI interface specification.



From a Perl interface perspective, the syntax of its interface is different, but



the idea is the same: You interface the database through the Win32::ODBC module from



your Perl code. I will not go into great detail about the Win32::ODBC module, as



it is currently available only on the Windows <BR>



platform. Questions about the module are addressed on a FAQ located at the following



URL:</P>



<PRE><A HREF="javascript:if(confirm('http://www.roth.net/ODBC/ODBCFAQ.HTM  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.roth.net/ODBC/ODBCFAQ.HTM'" tppabs="http://www.roth.net/ODBC/ODBCFAQ.HTM"><FONT COLOR="#0066FF">http://WWW.ROTH.NET/ODBC/ODBCFAQ.HTM



</FONT></A><FONT COLOR="#0066FF"></FONT></PRE>



<CENTER>



<H3><A NAME="Heading20"></A><FONT COLOR="#000077">Summary</FONT></H3>



</CENTER>



<P>In this chapter, we have seen how DBI can be used to greatly simplify building



a Web-based database interface. Now that database applications such as Oracle, Sybase,



and, on a somewhat different scale, Microsoft Access are being more widely used,



Perl provides a great way to access data via the Web. Now, a small company, with



a home-brewed Microsoft Access database, can easily write a Web interface to their



data. With DBI and ODBC, the database could be moved from Access to Oracle without



having to completely rewrite the Web interface.<BR>







<CENTER>



<P><A HREF="ch07.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch07.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37" ALIGN="BOTTOM"



BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42" HEIGHT="37" ALIGN="BOTTOM"



BORDER="2"></A><A HREF="ch09.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch09.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif" WIDTH="45" HEIGHT="37"



ALIGN="BOTTOM" BORDER="2"></A>



</CENTER>











</BODY>







</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -