Solved

Linking databases using cgi or perl

Posted on 1998-08-05
4
203 Views
Last Modified: 2010-03-05
How do I display the data from a database on a web site so that people may come and view it, make changes, buy things etc?
0
Comment
Question by:goanakin
4 Comments
 
LVL 5

Expert Comment

by:b2pi
ID: 1209025
What kind of database is is?
0
 
LVL 5

Expert Comment

by:n0thing
ID: 1209026
You could use Perl's DBI (Database Interface) and depending on
the database you use(Sybase, Oracle,...), you could install some
extra modules into perl in order to talk directly to the DB and
send the data back to the Web. It is a complex question and I can't have a precise answer to it. Check www.perl.com and the CPAN archive for the modules you need. All docs are online.
0
 

Expert Comment

by:kaijen
ID: 1209027
If you're working on a win32-basis you also could use the Win32::ODBC module. More information on databases with Win32 you'll find at http://www.geocities.com/SiliconValley/Way/6278/perl-win32-database.html

Best regards,
Kai.
0
 

Accepted Solution

by:
Christoph082498 earned 200 total points
ID: 1209028
If you want to acces an SQL Database this may help you. The script uses the WIN32::ODBC library which you can download from ftp.roth.com. I use this script as a formhandler  to display data of an Employeedatabase in an HTML-file.

if($ENV{'REQUEST_METHOD'} eq 'GET')  #  with this if  conditional I read the values
   {                                                         # of the elements in the previous form
    $Daten = $ENV{'QUERY_STRING'}      # both methods get and post can be used
   }
  else
   {
    read(STDIN, $Daten, $ENV{'CONTENT_LENGTH'});
   }

$Equal = index($Daten,"=")+1;                             # this is for splitting the string so that
$Datapart = substr($Daten, $Equal);                     # I can use the data
$Ampersand = index($Datapart, "&");
$Datapart1 = substr($Datapart, 0, $Ampersand);

use Win32::ODBC;                                     # this is the Win32::ODBC lib I mentioned

if(!($db = new Win32::ODBC("DSN=SCD; UID=UserID; PWD=Password;")))
{                  # The DSN you can set as a System DSN in Settings|ODBC32 if you use NT
   print "Error connecting to $DSN\n";
   print "Error: ". Win32::ODBC::Error() . "\n";
   exit;
}
$sq ="PUT YOUR SQL-STATEMENT HERE (E.G. SELECT * FROM TABLE) ";
if ($db->Sql($sql))
{
   print "SQL failed.\n";
   print "Error: " . $db->Error() . "\n";
   $db->Close();
   exit;
}
$i=0;
while ($db->FetchRow())         # Now I fill some arrays with the data from the database
{
   @name[$i]=$db->Data( "surname");
   @firstname[$i]=$db->Data("givenname");
   @telephone[$i]=$db->Data("telephonenumber");
   @department[$i]=$db->Data("department");
   @Email[$i]=$db->Data("internetaddress");
   @searchkey[$i]=$db->Data("searchkey");
   $i++;
}

# Now you can output an HTML page with print statements like these:

print "Content-Type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";

Just copy the HTML copy into the print statements.

To insert data into a listbox use a for statement like this:
print "<form name=\"EmployeeSurname\">\n";
print "    <p><select name=\"Surname\" size=\"1\" onChange=\"Eintragen()\">\n";
for($j=0; $j<$i; $j++)
   {
    print "<option><b>",@name[$j], " ", @firstname[$j], "</b>", ";", @department[$j],
           ";", @telephone[$j], ";", @Email[$j], ";", @searchkey[$j], "</option>\n";
   }
print "        </select>\n";

I hope this will help you

Christoph
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
transpose into pipe delemited 8 67
Replace  text in a file 2 97
.properties file to call function/method 9 59
combine multiple lines 2 41
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now