📄 ch10.htm
字号:
is IBM's own proprietary (and commercial) interface to their DB2
database system. It uses SQL statements to interact with the Web
server and generate HTML pages.
<LI><FONT COLOR=#000000>FileMaker Pro<BR>
</FONT>ROFM (<TT><FONT FACE="Courier"><A HREF="http://rowen.astro.washington.edu/">http://rowen.astro.washington.edu/</A></FONT></TT>)-This
is a freely available interface to FileMaker Pro databases. It
is only for Macintosh computers.
<LI><FONT COLOR=#000000>FoxPro<BR>
</FONT>FoxWeb (<TT><FONT FACE="Courier"><A HREF="http://www.foxweb.com/">http://www.foxweb.com/</A></FONT></TT>)-This
is a commercial product for Windows NT that allows Web server
integration with FoxPro databases.
<LI><FONT COLOR=#000000>GemStone<BR>
</FONT>GemStoneWWW (<TT><FONT FACE="Courier"><A HREF="http://ftp.tuwien.ac.at/~go/Implementation.html">http://ftp.tuwien.ac.at/~go/Implementation.html</A></FONT></TT>)-This
is a mini-HTTP server that handles requests that interface with
a GemStone Smalltalk database system. It is freely available.
<LI><FONT COLOR=#000000>General<BR>
</FONT>Amazon (<TT><FONT FACE="Courier"><A HREF="http://www.ieinc.com/webnews.htm">http://www.ieinc.com/webnews.htm</A></FONT></TT>)-This
is an all-purpose, commercial "legacy system" integrator.
That is, it takes data from Web forms and uses it to interact
with systems that were designed before the Web, such as Oracle,
Sybase, SQL Server, ODBC systems, and others.<BR>
DBI (<TT><FONT FACE="Courier"><A HREF="http://www.hermetica.com/techologia/DBI">http://www.hermetica.com/techologia/DBI</A></FONT></TT>)-DBI
is a database API (Application Programming Interface) for Perl.
It is sort of a catch-all set of functions, variables, and conventions
used to access any sort of database. There is currently support
for Oracle, mSQL, Ingres, Informix, Sybase, Empress, C-ISAM, DB2,
Quickbase, and Interbase databases, and more are in the works.
Like all good Perl software, this is absolutely free.<BR>
DBGate (<TT><FONT FACE="Courier"><A HREF="http://fcim1.csdc.com/DBGate/dbintro.htm">http://fcim1.csdc.com/DBGate/dbintro.htm</A></FONT></TT>)-This
is a commercial "serverless" database product. It interacts
directly with the database files (Access and FoxPro are currently
supported), thereby removing the need for ODBC or SQL communication
with a database server.<BR>
HyperStar WDK (<TT><FONT FACE="Courier"><A HREF="http://www.vmark.com/Products/WDK/index.html">http://www.vmark.com/Products/WDK/index.html</A></FONT></TT>)-This
(commercial) package acts as a go-between from the Web browser
to the server, interpreting database commands along the way. It
supports a large number of databases including Oracle, Sybase,
Informix, UniVerse, Ingres, Microfocus Cobol ISAM, and PI/open.
<BR>
mgyWeb (<TT><FONT FACE="Courier"><A HREF="http://www.mgy.ca/mgyweb/">http://www.mgy.ca/mgyweb/</A></FONT></TT>)-This
is a commercial solution for Windows 95 or NT that supports "many"
databases and any Windows 95-compatible Web server.<BR>
Sapphire/Web (<TT><FONT FACE="Courier"><A HREF="http://www.bluestone.com/products/sapphire">http://www.bluestone.com/products/sapphire</A></FONT></TT>)-This
is a commercial application builder that enables users to easily
create C/C++ CGI programs that interface with several popular
databases.
<LI><FONT COLOR=#000000> mSQL<BR>
</FONT>MsqlPerl (<TT><FONT FACE="Courier"><A HREF="ftp://Bond.edu.au/pub/Minerva/msql/Contrib/MsqlPerl-1.03.tar.gz">ftp://Bond.edu.au/pub/Minerva/msql/Contrib/MsqlPerl-1.03.tar.gz</A></FONT></TT>)-This
is a Perl interface to Msql that mimics the Msql API for the C
language. It allows on-the-fly updates of any mSQL database and
is freely available.
<LI><FONT COLOR=#000000>ODBC<BR>
</FONT>Cold Fusion (<TT><FONT FACE="Courier"><A HREF="http://www.allaire.com/cfusion/">http://www.allaire.com/cfusion/</A></FONT></TT>)-This
is a commercial product for Windows 95 and NT that has become
very popular in those circles. It allows for direct connectivity
to any ODBC database. It contains scads of features and an easy-to-use
interface.<BR>
DataRamp (<TT><FONT FACE="Courier"><A HREF="http://dataramp.com">http://dataramp.com</A></FONT></TT>)-A
commercial client/server/browser combo that allows secure read/write
access to any ODBM database (including Access).
<LI><FONT COLOR=#000000>Oracle<BR>
</FONT>Decoux (<TT><FONT FACE="Courier"><A HREF="http://www.abs.ee/~wow/htdocs/sdk10/decoux/">http://www.abs.ee/~wow/htdocs/sdk10/decoux/</A></FONT></TT>)-This
is a CGI interface to Oracle databases. It uses SQL statements
imbedded in HTML tags that are parsed before sending the results
to the client.<BR>
Oracle WWWIK (<TT><FONT FACE="Courier"><A HREF="http://www.abs.ww/~wow/htdocs/">http://www.abs.ww/~wow/htdocs/</A></FONT></TT>)-This
is a collection of CGIs and other tools to connect Oracle databases
to the Web. They are all freely available.<BR>
ORAlink (<TT><FONT FACE="Courier"><A HREF="http://oradb1.jinr/dubna.su/Software/ORALink">http://oradb1.jinr/dubna.su/Software/ORALink</A></FONT></TT>)-This
is a freeware product for Windows NT that uses CGI to access Oracle
databases from the Web.
<LI><FONT COLOR=#000000>SQL<BR>
</FONT>dbCGI (<TT><FONT FACE="Courier"><A HREF="http://www.progress.com/webtools/dbcgi/dbcgi.htm">http://www.progress.com/webtools/dbcgi/dbcgi.htm</A></FONT></TT>)-This
is a freely available C program that allows SQL statements to
be embedded into HTML files. A CGI program interprets the statements
and takes appropriate action before displaying the HTML to the
client.<BR>
GSQL (<TT><FONT FACE="Courier"><A HREF="http://www.santel.lu/SANTEL/SOFT/gsql_new.html">http://www.santel.lu/SANTEL/SOFT/gsql_new.html</A></FONT></TT>)-This
is a Mosaic only interface with SQL database servers. It is freely
available.<BR>
web.sql (<TT><FONT FACE="Courier"><A HREF="http://www.newmedia.sybase.com/Offerings/Websql/web_spec.html">http://www.newmedia.sybase.com/Offerings/Websql/web_spec.html</A></FONT></TT>)-This
is a free product from Sybase that allows SQL statements to be
imbedded into HTML files. The statements are then translated by
a CGI program, and the results are passed to the client.
<LI><FONT COLOR=#000000>Sybase<BR>
</FONT>Genera (<TT><FONT FACE="Courier"><A HREF="http://gdbdoc.gdb.org/letovsky/genera/genera.html">http://gdbdoc.gdb.org/letovsky/genera/genera.html</A></FONT></TT>)-This
is a freely available package that integrates Sybase databases
with the Web. It supports Web page generation from Sybase databases
and HTML form queries.<BR>
Sybase WWW Tools (<TT><FONT FACE="Courier"><A HREF="http://www.sybase.com/WWW/">http://www.sybase.com/WWW/</A></FONT></TT>)-A
collection of CGIs and other tools for integrating Sybase databases
for the Web. Freely available.
</UL>
<P>
This is nowhere near a complete list of CGI resources for databases,
and new products are being developed constantly. Consider this
a jumping-off point to explore the possibilities. But suppose
you've painstakingly checked out all of the products available,
and you still cannot find a CGI program to meet your needs. All
is not lost. By using common tools found on many Web sites, it
may be possible to build your own CGI to interact with your database
server of choice.
<P>
Consider the address book example from the beginning of the chapter.
How could that be accomplished with a database server? First we
need to decide on the right tools for the job. A good freely available
database is mSQL (<TT><FONT FACE="Courier"><A HREF="http://www.hughes.com.au/">http://www.hughes.com.au/</A></FONT></TT>).
It offers most of the functionality of a full-fledged SQL server,
with low overhead and easy installation. The mail mSQL distribution
comes with a C API and function library, but we'll stick with
Perl just 'cause it's cool. There are several mSQL interfaces
for Perl, some of which were mentioned in the preceding section.
We'll use MsqlPerl for no particular reason (I've found that all
of the Perl mSQL interfaces work fairly well).
<P>
The MsqlPerl module provides direct emulation of the C API functions.
You can submit queries to the database which add, select, delete,
and modify the database directly.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
There are two things to be aware of here. First, the program <TT><FONT FACE="Courier">msqld</FONT></TT> must be running on whatever machine the database is stored on. This need not be the same machine as the Web server because the API provides functions to
connect to a remote mSQL server.
</BLOCKQUOTE>
<BLOCKQUOTE>
Secondly, <TT><FONT FACE="Courier">MsqlPerl</FONT></TT> is compiled as a dynamically loaded extension to Perl. Certain systems have trouble dynamically loading from Perl (notably AIX and non-ELF Linux). If your MsqlPerl script is failing, make sure that
your copy of Perl is able to dynamically load properly.
</BLOCKQUOTE>
</TD></TR>
</TABLE></CENTER>
<P>
<P>
We can use the same HTML form pages we used for the text database
example. The first form searched an existing database. The appropriate
CGI program is shown in Listing 10.3.
<HR>
<BLOCKQUOTE>
<B>Listing 10.3. Searching an SQL database.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">#!/bin/perl<BR>
<BR>
require cgi_read; # Set up CGI environment<BR>
use Msql; # Load the Msql module (See note above for a caveat.)
<BR>
<BR>
$dbh = Connect Msql; # Connect to the local mSQL server<BR>
<BR>
SelectDB $dbh "addresses"; # Selected the "addresses
database. Assume that<BR>
#
it already exists. mSQL comes with a utility<BR>
#
called 'msqladmin' which can create databases.<BR>
<BR>
$all = "name, phone, street, city, state, zip"; # All
address fields<BR>
$query = ""; # Set aside a variable to hold the query.
<BR>
<BR>
foreach (keys %FORM) { #
Gather all existing form requests into<BR>
$query =. " $_ = $FORM{'$_'} AND"; #
one line.<BR>
}<BR>
$query =~ s/AND$//;
# Get rid of that annoying trailing 'AND'<BR>
<BR>
$sth = Query $dbh "SELECT $all FROM addresses WHERE $query";
# Send query<BR>
<BR>
print "<HTML><HEAD><TITLE>Search Results</title></head><BODY>\n";
<BR>
<BR>
$I = 0; # 0 mean no results.<BR>
while (@arr = FetchRow $sth) {<BR>
if ($I == 0) { $I = 1; } # 1 means 1 results
<BR>
if ($I == 1) { # Print success message
<BR>
print "<H4>Your
search results are listed below</h4>";<BR>
print "<PRE>\n";
<BR>
};<BR>
$I++;<BR>
# Print results one at a time.<BR>
print <<EOF;<BR>
-- --<BR>
<BR>
Name: $arr[0]<BR>
Phone: $arr[1]<BR>
Street: $arr[2]<BR>
City: $arr[3]<BR>
State: $arr[4]<BR>
Zip: $arr[5]<BR>
<BR>
EOF<BR>
}<BR>
if ($I == 2) {<BR>
print "</pre><br>";
<BR>
print "<A HREF=\"addrbk.html\">Go</a>
back to the form to make another<BR>
Âsearch.<br>\n";<BR>
print "</body></html>\n";
<BR>
} elsif ($I == 0) {<BR>
print <<EOE;<BR>
<HTML><HEAD><TITLE>Search Failed!</title></head><BODY>
<BR>
<h4>There are no entries which match your criteria</h4>
<BR>
<A HREF="addrbk.html">Go</a> back to the
form to make another search.<BR>
</body></html><BR>
EOE<BR>
}</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
The actual CGI code in this case is about one quarter the size
of the equivalent CGI in the first example. In addition, it is
trivial to add substring matching to an mSQL query. Also note
the distinct absence of ID numbers. mSQL is a relational, random
access database. That is, it does not need to read in all entries
to access any one of them.
<P>
The real power of a database server becomes apparent when modifying
the database itself.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Because the modification of the database is done by the server itself, the file permission issues of text databases do not apply here. Instead, most database servers have their own access rights schema that can be used to allow only select users to access
certain databases.</BLOCKQUOTE>
</TD></TR>
</TABLE></CENTER>
<P>
<P>
Now we consider the CGI required to add entries to the database.
Once again, we assume the a database called <TT><FONT FACE="Courier">addresses</FONT></TT>
exists that contains a table called <TT><FONT FACE="Courier">addresses</FONT></TT>.
<BLOCKQUOTE>
<TT><FONT FACE="Courier">#!/bin/perl<BR>
<BR>
require cgi_head;<BR>
use Msql;<BR>
<BR>
$dbh = Connect Msql; # connect to the local mSQL server<BR>
<BR>
SelectDB $dbh "addresses" # select the 'addresses' database
<BR>
<BR>
Query $dbh "INSERT INTO addresses ( name, phone, street,
city, state, zip ) VALUES<BR>
Â('$FORM{'name'}, $FORM{'phone'}, $FORM{'street'}, $FORM{'city'},
$FORM{'zip'} )";<BR>
<BR>
print <<EOF;<BR>
<HTML><HEAD><TITLE>Addition successful</title><head><BODY>
<BR>
Your entry has been added to the address book.<BR>
<A HREF="add.html">Go</a> back to the form
to add another entry.<BR>
</body></html><BR>
EOF</FONT></TT>
<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -