![]() | ![]() | ![]() | ![]() | ![]() |
This example shows you how to access data using the "mSQL" (free) database program. The database we will process is called "supersite" and the table we will access is "link".
This example makes use of Mark Hessing's RexxSQL library to access the database program. It's free and is available for multiple operating systems and can access many different database programs. Its available from "http://www.lightlink.com/hessling/".
You may want to have a look at the #evaluate routines AsIs() and AutoTag().
;--- Very simplistic start of HTML ------------------------------------------ <HTML> <BODY> <H1>Example - Create Links List from SQL Query</H1> ;--- Initialization --------------------------------------------------------- #define QueryCategory 3 ;;This query is for this category #define LinkTemplate <P><A HREF="{$url}">{$title}</A>: {$description} ;;HTML for each record (note that it would be more efficient (but less "clean") to just pick up rexx variable names here ;--- Enable PPWIZARD to make use of external SQL library -------------------- #evaluate '' "call RXFuncAdd 'SQLLoadFuncs', 'rexxsql', 'SQLLoadFuncs'" #evaluate '' "call SQLLoadFuncs;" ;--- Connect to the data base ("supersite" on local machine) ---------------- #evaluate 'ConnectRc' "SQLConnect('PPW',,, 'supersite', 'localhost')" ;--- Perform a database query (on the table "link") ------------------------- #evaluate+ 'QueryRc' ^SQLCommand('RxLink', 'SELECT * FROM link WHERE category = <$QueryCategory>')^ #info 'QueryRc = <$QueryRc>' #info 'Number of records is <??RxLink.url.0>' ;--- Generate the html (for simple list) ------------------------------------ <UL> ;;Start of list #RexxVar RxCount = 1 ;;Initialize record counter (rexx variable) #{ ;;Start of loop #if ['<??RxCount>' <= '<??RxLink.url.0>'] ;--- Use previously defined macro (template) to generate output ------ <$LinkTemplate url="<??RxLink.url.RxCount>" title=^<??RxLink.title.RxCount>^ description=^<??RxLink.description.RxCount>^> #RexxVar RxCount + 1 ;;Update record counter #elseif #break #endif #} ;;End of loop </UL> ;;End of list ;--- Disconnect the data base ----------------------------------------------- #evaluate 'DisConnectRc' "SQLDisconnect('PPW')" ;--- Very simple end of HTML ------------------------------------------------ <P> <HR> <CENTER>End of simple SQL IMPORT Example</CENTER> </BODY> </HTML>
![]() | ![]() | ![]() | ![]() | ![]() |