Linking databases using cgi or perl

Posted on 1998-08-05
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?
Question by:goanakin

Expert Comment

Comment Utility
What kind of database is is?

Expert Comment

Comment Utility
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 and the CPAN archive for the modules you need. All docs are online.

Expert Comment

Comment Utility
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

Best regards,

Accepted Solution

Christoph082498 earned 200 total points
Comment Utility
If you want to acces an SQL Database this may help you. The script uses the WIN32::ODBC library which you can download from 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
    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";
if ($db->Sql($sql))
   print "SQL failed.\n";
   print "Error: " . $db->Error() . "\n";
while ($db->FetchRow())         # Now I fill some arrays with the data from the database
   @name[$i]=$db->Data( "surname");

# 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


Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

11 Experts available now in Live!

Get 1:1 Help Now