Switch layouts home | FAQ | | P1 | P2 | P3 | P4 | P5 |  | A1 | A2 | A3  | | B1

Database Access

1. Create a copy or a link to PB. It may be either a hard link or a symbolic link depending on your preferences and settings of the web server. The name of the link can be anything as long as the web server is going to run it as a cgi script. For example, a1.cgi
ln ../cgi-bin/pb.pl ./a1.cgi    or
ln -sf ../cgi-bin/pb.pl ./a1.cgi

2. Create a project configuration file. The name should be cgi-script's name + ".pm". For a1.cgi this file should be ./a1.cgi.pm
use vars qw($dbh $sth);
use DBI;
use pb_dblib;

$DEBUG{all}=DBG_ALL;
$DEBUG_CMD{all}=DBG_ALL;


$templatesdir="sampledir";

$DB_Server = 'pb.zayki.com';
$DB_Db='pb_demo';
$DB_User='pb_demo';
$DB_Password='pbpass';
$DB_Driver='mysql';
$DB_Tb='sample';
$Db_FirstName='first_name';
$Db_LastName='last_name';
$Db_YearBorn='year_born';


$Parameter{Page}="home"; 
$Template{home}="$templatesdir/a1-home.html";

#-- data for the web page content ---

sub gettableheader
{
  sqlconnect();
  @retarr=sqlget("show columns from sample from $DB_Db");
  sqldisconnect();
  return(@retarr);
}
sub getpeopleinfo
{
  sqlconnect();
  @retarr=sqlget("select * from $DB_Db.$DB_Tb");
  sqldisconnect();
  return(@retarr);
}

1;

3. Create an html-template file, a1-home.html
Let's see what we've got in our database:
<!%set @theader=&gettableheader()%>
<!%set @tbody=&getpeopleinfo()%>
<TABLE border="1">
<TR>
<!%for($i=0;$theader[$i][0];$i++)%><TD><!%show $theader[$i][0]%></TD><!%endfor%>
</TR>
<!%for($i=0;$tbody[$i][0];$i++)%>
<TR>
<!%for($j=0;$tbody[$i][$j];$j++)%>
<TD><!%show $tbody[$i][$j]%></TD>
<!%endfor%>
</TR>
<!%endfor%>
</TABLE>

4. This web project is complete. Check it out:
/PB/a1.cgi


2002-03