ScriptBasic

Support => ScriptBasic Examples w/source => Topic started by: Support on March 27, 2006, 01:45:03 am

Title: CGI - ODBC Example
Post by: Support on March 27, 2006, 01:45:03 am
http://www.scriptbasic.org/cgi-bin/odbctest.bas

(http://www.scriptbasic.org/forum/link_docs/test_table.gif)

Code: [Select]
#!/usr/bin/scriba -c

INCLUDE cgi.bas
INCLUDE odbc.bas

cgi::Header 200,"text/html"
cgi::FinishHeader

PRINT """
<HTML>
<HEAD>
<title>unixODBC testing</title>
</HEAD>
<BODY>
<FONT face="Verdana, Arial, Helvetica, sans-serif">
<TABLE border="1" cellpadding="3">
"""

ON ERROR GOTO PROBLEMS

dbh = ODBC::RealConnect("DSN","user","password")

ODBC::query(dbh,"SELECT * FROM contact")

PRINT "File Handle: <b>",dbh,"</b><br>"
PRINT "Affected Rows: <b>",ODBC::AffectedRows(dbh),"</b><br>"

WHILE ODBC::FetchHash(dbh,column)

PRINT "<TR>"
PRINT "<TD>",column{"ID"},"</TD>"
PRINT "<TD>",column{"NAME"},"</TD>"
PRINT "<TD>",column{"ADDRESS"},"</TD>"
PRINT "<TD>",column{"CITY"},"</TD>"
PRINT "<TD>",column{"STATE"},"</TD>"
PRINT "<TD>",column{"ZIP"},"</TD>"
PRINT "<TD>",column{"PHONE"},"</TD>"
PRINT "<TD>",column{"EMAIL"},"</TD>"
PRINT "<TD>",column{"URL"},"</TD>"
PRINT "</TR>"

WEND

PRINT """
</TABLE>
</FONT>
</BODY>
</HTML>
"""

ODBC::Close(dbh)

END

PROBLEMS:

PRINT "ERROR = ",error(),"<br>"

RESUME