Skip to content

Files

Latest commit

09ebf68 · Apr 6, 2019

History

History
99 lines (74 loc) · 2.42 KB

example03.md

File metadata and controls

99 lines (74 loc) · 2.42 KB

PgBash example-03


Example of a Web application.(PgBash)


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>

<FORM METHOD="POST" ACTION="/cgi-bin/**webapi.cgi**">

Database 
         <input type="text" name="**pgdatabase**" length=32>
Username 
         <input type="text" name="**pguser2**" length=32>
Password 
         <input type="text" name="**pgpassword2**" length=32>

<INPUT TYPE=SUBMIT VALUE="submit">
</FORM>

</BODY>
</HTML>

Web application (CGI) -- "webapi.cgi"

#!/usr/local/bin/pgbash
##########################################################################
#  "webapi.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 email tel kind ....
1220 XXXXXXX [email protected] 0726-76-9999 *
1249 XXXXXX [email protected] 090-7103-9999 *
1217 XXXX [email protected] 042-571-9999 NET
1221 XXXX [email protected] 0726-27-9999 *
1250 XXXX [email protected] 06-6622-9999 *
1271 XXXXX [email protected] 06-6872-9999 *
1222 XXXX [email protected] 0798-72-9999 *
1212 XXXX [email protected] 0725-20-9999 *
1203 XXXX [email protected] 0742-40-9999 *
1223 XXXX [email protected] 0742-45-9999 *