Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Support

Pages: 1 ... 10 11 [12]
166
ScriptBasic Examples w/source / CGI - MySQL Example
« on: March 26, 2006, 05:42:01 PM »


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

INCLUDE cgi.bas
INCLUDE mysql.bas

OPTION cgi$Method cgi::Post or cgi::Get

dbh = mysql::RealConnect("host","user","password","database")

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

cgi::Header 200,"text/html"

cgi::FinishHeader

PRINT """
<HTML>
<HEAD>
<title>mySQL testing</title>
</HEAD>
<BODY>
"""
PRINT """<FONT face="Verdana, Arial, Helvetica, sans-serif">"""

PRINT """<TABLE border="1" cellpadding="3">"""

WHILE mysql::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>"

PRINT "<BR>"
PRINT "The database handle is: <b>",dbh,"</b><BR>"
PRINT "Affected rows by SELECT: <b>",mysql::AffectedRows(dbh),"</b><BR>"
PRINT "Character set name is: <b>",mysql::CharacterSetName(dbh),"</b><BR>"
PRINT "Last error is: <b>",mysql::ErrorMessage(dbh),"</b><BR>"
PRINT "Client info is: <b>",mysql::GetClientInfo(),"</b><BR>"
PRINT "Host info is: <b>",mysql::GetHostInfo(dbh),"</b><BR>"
PRINT "Proto info is: <b>",mysql::GetProtoInfo(dbh),"</b><BR>"
PRINT "Server info is: <b>",mysql::GetServerInfo(dbh),"</b><BR>"
PRINT "PING result: <b>",mysql::Ping(dbh),"</b><BR>"
PRINT "Thread ID: <b>",mysql::ThreadId(dbh),"</b><BR>"
PRINT "Status is: <b>",mysql::Stat(dbh),"</b><BR>"

PRINT "</FONT>"

PRINT """
</BODY>
</HTML>
"""

mysql::Close(dbh)

END

167
ScriptBasic Examples w/source / CGI - echo.bas
« on: March 26, 2006, 05:36:09 PM »
This example posts to itself so you can see some of the features of the CGI extension module.

http://www.scriptbasic.org/cgi-bin/echo.bas

Code: [Select]
#! /usr/bin/scriba -c
global const nl = "\n"
Const NumberOfCookies = 3

include cgi.bas

option cgi$Method cgi::Get or cgi::Upload

' cgi::RequestBasicAuthentication "login password"
cgi::Header 200,"text/html"

'
' We are setting several cookies. The expiry time is ten seconds so you can test that
' the cookies are sent by the browser if you press some of the buttons fast enough,
' but it does not if you are slow
'
for i=1 to NumberOfCookies
  ' cookie(i) is i, no domain is defined, path is /, expires after 10 seconds, not secure
  cgi::SetCookie "cookie" & i,i,undef,"/",gmtime()+10,false
next i

cgi::FinishHeader

'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>CGI parameter testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>View CGI Parameters</H1>
This page shows the cgi parameters the way it was uploaded.
<!-- here is the result of the previous HTTP request -->
<FONT SIZE="3">
<PRE>

CGI system variables
--------------------

"""
'-------------------------------------------------------

print "ServerSoftware  = ",cgi::ServerSoftware(), nl
print "ServerName      = ",cgi::ServerName(), nl
print "GatewayInterface= ",cgi::GatewayInterface(),nl
print "ServerProtocol  = ",cgi::ServerProtocol(), nl
print "ServerPort      = ",cgi::ServerPort(), nl
print "RequestMethod   = ",cgi::RequestMethod(), nl
print "PathInfo        = ",cgi::PathInfo(), nl
print "PathTranslated  = ",cgi::PathTranslated(), nl
print "ScriptName      = ",cgi::ScriptName(), nl
print "QueryString     = ",cgi::QueryString(), nl
print "RemoteHost      = ",cgi::RemoteHost(), nl
print "RemoteAddress   = ",cgi::RemoteAddress(), nl
print "AuthType        = ",cgi::AuthType(), nl
print "RemoteUser      = ",cgi::RemoteUser(), nl
print "RemoteIdent     = ",cgi::RemoteIdent(), nl
print "ContentType     = ",cgi::ContentType(), nl
print "ContentLength   = ",cgi::ContentLength(), nl
print "UserAgent       = ",cgi::UserAgent(), nl
print "Cookie          = ",cgi::RawCookie(), nl

print "Referer         = ",cgi::Referer(),nl
print "Password        = ",Environ("HTTP_PASSWORD"),nl
print "Full auth string= ",Environ("HTTP_AUTHORIZATION"),nl
print "\nCookies:\n"
for i=1 to NumberOfCookies
  print "cookie" & i," ",cgi::Cookie("cookie" & i),"\n"
next i

print "Text field using Param(\"TEXT-FIELD\") is ",cgi::Param("TEXT-FIELD"),nl,nl


if cgi::RequestMethod() = "GET" then
  print "GET text field using GetParam(\"TEXT-FIELD\") is ",cgi::GetParam("TEXT-FIELD"),nl
end if

if cgi::RequestMethod() = "POST" then
  print "POST text field using PostParam(\"TEXT-FIELD\") is ",cgi::PostParam("TEXT-FIELD"),nl
  if cgi::ContentType() like "multipart*" then
    print "Original file name is ",cgi::FileName("FILE-UPLOAD-NAME"),nl
    if cgi::FileLength("FILE-UPLOAD-NAME") > 0 then
      print "File with a length of ",cgi::FileLength("FILE-UPLOAD-NAME")," bytes was saved\n"
      on error goto NoSave
      cgi::SaveFile "FILE-UPLOAD-NAME","/var/www/vhosts/scriptbasic.org/httpdocs/upload/newup.txt"
    else
      print "There is no uploaded file."
    end if
  end if
end if

print """</PRE><TABLE><TR><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to POST parameters:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
</FORM>
</PRE></TD><TD BORDER=1 width="20">&nbsp;</TD><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to GET parameters:<BR>
<FORM METHOD="GET" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
</FORM>
</PRE></TD></TR></TABLE><PRE>
<hr>
A simple form to UPLOAD a file:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas" ENCTYPE="multipart/form-data">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="FILE" VALUE="FILE-UPLOAD-VALUE" NAME="FILE-UPLOAD-NAME">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE="UPLOAD FILE">
</FORM>
<hr>
</BODY>
</HTML>
"""
stop
NoSave:

print "An error has happened saving the file. Code =",error(),nl

resume next

John

Pages: 1 ... 10 11 [12]