Perl Version | PHP Version |
---|---|
use Wacs; use DBI; |
require_once "wacs.php"; require_once "DB.php"; |
Perl Version | PHP Version |
---|---|
# initialise WACS: read the Wacs configuration files read_conf; # check the auth(entication and authorisation) of this user check_auth( $ENV{"REMOTE_ADDR"}, 1 ); |
$wacs = new Wacs; // read the Wacs configuration files $wacs->read_conf(); // check the auth(entication and authorisation) of this user $wacs->check_auth( $_SERVER['REMOTE_ADDR'], 1 ); |
The third step is to establish the connection to the database backend
and ready it for a query. The first four lines of this code deal with
ensuring the appropriate environment variable is set such that the
database will find it's binaries, libraries and configuration files in
the location they've been installed on the host. This is often not a
problem with open-source packages like MySQL which come with the OS and
are therefore in a known location, but they are needed for commercial
databases like Oracle. Once again, here's the same code in both the
Perl and PHP dialects:
Perl Version | PHP Version |
---|---|
$dbienv = conf_get_attr( "database","dbienvvar" ); if( $dbienv ne "" ) { $ENV{$dbienv}= conf_get_attr( "database","dbienvvalue" ); } $dbhandle=DBI->connect( conf_get_attr("database","dbiconnect"), conf_get_attr("database","dbuser"), conf_get_attr("database","dbpass") ) || die("Can't connect to database\nReason given was $DBI::errstr\n"); |
// database initialisation $dbienv = $wacs->conf_get_attr("database","dbienvvar"); if( ! empty( $dbienv )) { putenv($dbienv."=".$wacs->conf_get_attr("database","dbienvvalue")); } $dbhandle= DB::connect( $wacs->conf_get_attr("database","phpdbconnect") ); if( DB::iserror($dbhandle)) { print "Can't connect to database\n"; } |
Having initialised the Wacs subsystem as shown above, you then need to run a suitable database query and display the results. To do this effectively, you will need some understanding of how the database schemas are designed and what sort of data each table contains. The next page covers these aspects.
The first step is to create and run a suitable SQL query against the
database, once again the same query is implemented in both Perl and
PHP:
Perl Version | PHP Version |
---|---|
# 0 1 2 3 $cutesql = "select mname, modelno, mbigimage, mimage from "; $cutesql.= conf_get_attr("tables","models")." "; $cutesql.= "where mflag = 'C' order by mname "; $cutecsr=$dbhandle->prepare( $cutesql ); $cutecsr->execute; while( @cuterec = $cutecsr->fetchrow_array ) { print "Model: ".$cuterec[0]." Number:".$cuterec[1]."\n"; } |
// 0 1 2 3 $cuterec = $dbhandle->getAll("select mname, modelno, mbigimage, mimage from ". $wacs->conf_get_attr("tables","models"). " where mflag = 'C' order by mname"); $entryno = 0; while( isset( $results[$entryno] )) { print "Model: ".$cuterec[$entryno][0]." Number:". $cuterec[$entryno][1]."\n"; $entryno++; } |
The small sized headshot, mimage, is assumed to be present for all
models, and it will be located at:
wacs/icons/vendor/modelname.jpg
on the web server. We can get the URL for the wacs
part from the Wacs configuration files which have already been read
by this point - the function call is simply:
Perl: | conf_get_attr("server","wacsurl") |
---|---|
PHP: | $wacs->conf_get_attr("server","wacsurl") |
Perl Version | PHP Version |
---|---|
# link to the model page, thumbs version print "<a href=\"".conf_get_attr("server","cgiurl"); print "wacsmpthumbs/".$cuterec[1]."\">"; # add in the icon print "<img src=\"".conf_get_attr("server","wacsurl"); print "icons/".$cuterec[3]."\" alt=\"[image: ".$cuterec[0]."]\">"; # print the name, close the link print $cuterec[0]."</a>\n"; |
// link to the model page, thumbs version print "<a href=\"".$wacs->conf_get_attr("server","cgiurl"); print "wacsmpthumbs/".$cuterec[$entryno][1]."\">"; // add in the icon print "<img src=\"".$wacs->conf_get_attr("server","wacsurl"); print "icons/".$cuterec[$entryno][3]."\" alt=\"[image: "; print $cuterec[$entryno][0]."]\">"; // print the name, close the link print $cuterec[$entryno][0]."</a>\n"; |