Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI and Postgrsql -- Linux 7.2

Status
Not open for further replies.

progolf069

Programmer
Jun 13, 2001
37
US
I am now in the stages I am ready to start accessing one of my many Postgrsql Databases that I have installed on my Redhat Linux 7.2 machine. I have CGI working correctly, and my databases are working just fine from the command line (in telnet), but now I want to integrate the databases to the web side of things.

Currently I have this script written:

Code:
#!/usr/bin/perl

# database.cgi -- does database lookups!
# my first -- database to web output script!+

#PATH='/usr/local/pgsql/bin:/bin';

print "Content-type: text/html\n\n";

print <<&quot;EOF&quot;;

print '<html><head><title>ICD9 Med Codes</title></head><body>';

print 'psql med2000 -U ian -H -c &quot;SELECT * FROM icd9;&quot;';

print '</body></html>';

EOF

When I execute the above script, I don't access the server, I only print out the psql med2000..... line. This is understood, and I know why that is happening. Is there anyway that I can do like a system call for that command to be processed on the server and then have it display the results? When I execute the command on the server's command line (in telnet) it automatically generates (the -H attribute of that string) all of the HTML code for you example of the output:

Code:
<table border=1>
  <tr>
    <th align=center>trans_num</th>
    <th align=center>icd9_diag</th>
  </tr>
  <tr valign=top>
    <td align=left>001    </td>
    <td align=left>Cholera^M</td>
  </tr>
  <tr valign=top>
    <td align=left>001.0  </td>
    <td align=left>Due to Vibrio cholerae^M</td>
  </tr>
  <tr valign=top>
    <td align=left>001.1  </td>
    <td align=left>Due to Vibrio cholerae el tor^M</td>
  </tr>
  <tr valign=top>
    <td align=left>001.9  </td>
    <td align=left>Cholera, unspecified^M</td>
  </tr>
... continues on....


Any suggestions?

Basic question-- is there anyway that I can run that command (psql med2000 -U ian -H -c &quot;SELECT * FROM icd9;&quot;) on the server side and return the results to the user (on the web)?

Thanks for your assistance and any feedback you give!
 
Yes this is a PERL question acctually. You can use the system() command in perl to do this particualar function and return() the output to the perl script and output the datat to the browser.

Also you can access the database directly through perl using the DBI module.

Check the man pages in perl on system() and return().
 
Haunter,

Thanks for the reply. I was getting desparate at the time I posted this message. I ended up using the DBI method. I will take in to consideration next time using the system and return functions.

Thanks for your feedback!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top