Database Reference
In-Depth Information
for User and Group directives in the httpd.conf configuration file.) If you expect web
scripts to read and write files, those files must be accessible to the account used to run
the web server. For example, if your server runs under the nobody account and you want
a script to be able to store uploaded image files into a directory called uploads in the
document tree, that directory must be readable and writable by the nobody user.
Another implication is that if other people can write scripts to be executed by your web
server, those scripts too run as nobody and they can read and write the same files as your
own scripts. That is, files used by your scripts cannot be considered private only to your
scripts. A solution to this problem is to use the Apache suEXEC mechanism. (If you use
an ISP for web hosting, suEXEC might be enabled already.)
Perl
Our first web-based Perl script retrieves and displays a list of tables in the cookbook
database. It produces HTML elements using the CGI.pm module, which makes it easy
to write web scripts without writing literal HTML tags. CGI.pm provides an object-
oriented interface and a function call interface, so you can use it to write web pages in
either of two styles. Here's a script, show_tables_oo.pl , that produces the table listing
using the object-oriented interface:
#!/usr/bin/perl
# show_tables_oo.pl: Display names of tables in cookbook database
# (uses the CGI.pm object-oriented interface)
use strict ;
use warnings ;
use CGI ;
use Cookbook ;
# Create CGI object for accessing CGI.pm methods
my $cgi = new CGI ;
# Print header, blank line, and initial part of page
print $cgi -> header ();
print $cgi -> start_html ( - title => "Tables in cookbook Database" );
print $cgi -> p ( "Tables in cookbook database:" );
# Connect to database, display table list, disconnect
my $dbh = Cookbook:: connect ();
my $stmt = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'cookbook' ORDER BY TABLE_NAME" ;
my $sth = $dbh -> prepare ( $stmt );
$sth -> execute ();
while ( my @row = $sth -> fetchrow_array ())
 
Search WWH ::




Custom Search