Example of a Web application.
HTML
<HTML> <HEAD> <META HTTP-EQUIV=Content-Language CONTENT=ja> <META HTTP-EQUIV=Content-Type CONTENT='text/html; charset=UTF-8'> </HEAD> <BODY BGCOLOR=#DDDDDD> Database <input type="text" name="PGDATABASE" length=32> Username <input type="text" name="PGUSER2" length=32> Password <input type="text" name="PGPASSWORD2" length=32> </BODY> </HTML>
Web application (CGI)
#!/usr/local/bin/pgbash ########################################################################## # "select1.cgi" # # $PGDATABASE # database name # $PGUSER2 # database user # $PGPASSWORD2 # database password # ########################################################################## exec 2>&1 echo "Content-type: text/html" echo "" set EXEC_SQL_OPTION CGI; #--------- start HTML ---------- echo "<HTML>" echo "<HEAD>" echo "<META HTTP-EQUIV=Content-Language CONTENT=ja>" echo "<META HTTP-EQUIV=Content-Type CONTENT='text/html; charset=UTF-8'>" echo "</HEAD>" echo "<BODY BGCOLOR=#DDDDDD>" #-------- connect to DATABASE --------- connect to $PGDATABASE user $PGUSER2 $PGPASSWORD2; if(( SQLCODE != 0 )); then exit fi #---------- client_encoding ----------- set client_encoding='UTF8'; #------------ execute SQL ------------- select * from member; if (( SQLCODE == 0 && SQLNTUPLE == 0 )); then echo "<H2>Data not found.</H2>" fi #------- disconnect DATABASE ---------- disconnect all; echo "</BODY>" echo "</HTML>"
Output
userid name tel kind .... 1220 XXXXXXX mmmmmmmm@nifty.ne.jp 0726-76-9999 * 1249 XXXXXX mmmmmmm@email.ne.jp 090-7103-9999 * 1217 XXXX mmmmmmmm@nifty.ne.jp 042-571-9999 NET 1221 XXXX mmmmm@mbg.sphere.ne.jp 0726-27-9999 * 1250 XXXX mmmmmmm@oct.zaq.ne.jp 06-6622-9999 * 1271 XXXXX mmmmmmmm@nifty.ne.jp 06-6872-9999 * 1222 XXXX mmmmmmmm@nifty.ne.jp 0798-72-9999 * 1212 XXXX mmmmmm@sannet.ne.jp 0725-20-9999 * 1203 XXXX mmmm@computer.com 0742-40-9999 * 1223 XXXX mmmmmmmm@nifty.ne.jp 0742-45-9999 *