Announcement

Collapse
No announcement yet.

PB-CGI - Database (MySQL)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB-CGI - Database (MySQL)

    Working with databases in PowerBASIC CGI under PluriBASIC is very simple:

    Code:
    [FONT="Courier New"][B]
    [COLOR="Blue"]#COMPILE[/COLOR] [COLOR="Black"]EXE[/COLOR]
    [COLOR="Blue"]#DIM[/COLOR] [COLOR="Blue"]ALL[/COLOR]
    [COLOR="Blue"]#PROJECT[/COLOR] [COLOR="DarkGreen"]"windows"[/COLOR]
    [COLOR="Blue"]#FTPLOC[/COLOR]  [COLOR="DarkGreen"]"examples"[/COLOR]
    [COLOR="Blue"]#ODBCDRV[/COLOR] [COLOR="DarkGreen"]"MySQL ODBC 5.2 Unicode Driver"[/COLOR]
    [COLOR="Blue"]#DATABASE[/COLOR] [COLOR="Blue"]OPEN[/COLOR]
    [COLOR="Blue"]#BROWSER[/COLOR] [COLOR="Blue"]CHROME[/COLOR]
    
    [COLOR="Red"]%MALE[/COLOR]   [COLOR="Black"]=[/COLOR] [COLOR="Black"]1[/COLOR]
    [COLOR="Red"]%FEMALE[/COLOR] [COLOR="Black"]=[/COLOR] [COLOR="Black"]2[/COLOR]
    
    [COLOR="Blue"]TYPE[/COLOR] [COLOR="Black"]WebExampleTable[/COLOR] 
        [COLOR="Black"]ID[/COLOR]     [COLOR="Blue"]AUTOINC[/COLOR] [COLOR="Blue"]NOTNULL[/COLOR] [COLOR="Blue"]PRIMARY[/COLOR] [COLOR="Blue"]ISCOND[/COLOR] [COLOR="Blue"]AS[/COLOR] [COLOR="Blue"]LONG[/COLOR]
        [COLOR="Black"]Age[/COLOR]    [COLOR="Blue"]AS[/COLOR] [COLOR="Blue"]LONG[/COLOR]
        [COLOR="Blue"]NAME[/COLOR]   [COLOR="Blue"]AS[/COLOR] [COLOR="Blue"]STRING[/COLOR]
        [COLOR="Black"]Gender[/COLOR] [COLOR="Blue"]AS[/COLOR] [COLOR="Blue"]LONG[/COLOR]
    [COLOR="Blue"]END[/COLOR] [COLOR="Blue"]TYPE[/COLOR]
    
    [COLOR="Blue"]FUNCTION[/COLOR] [COLOR="Black"]MAIN[/COLOR] [COLOR="Blue"]AS[/COLOR] [COLOR="Blue"]LONG[/COLOR]
    
    [COLOR="Silver"]' At this point, the script starts with Database open.[/COLOR]
    [COLOR="Silver"]' Lets define a user-defined type for queriyng our database.[/COLOR]
    [COLOR="Blue"]LOCAL[/COLOR] [COLOR="Black"]Fld[/COLOR] [COLOR="Blue"]AS[/COLOR] [COLOR="Black"]WebExampleTable[/COLOR]
    
    [COLOR="Silver"]' Make sure our table exists[/COLOR]
    [COLOR="Blue"]IF[/COLOR] [COLOR="Blue"]ISFALSE[/COLOR][COLOR="Black"]([/COLOR][COLOR="Blue"]MYSQL_TABLE_EXISTS[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld[/COLOR][COLOR="Black"])[/COLOR][COLOR="Black"])[/COLOR] [COLOR="Blue"]THEN[/COLOR]
        [COLOR="Blue"]CALL[/COLOR] [COLOR="Blue"]MYSQL_CREATE_TABLE[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld[/COLOR][COLOR="Black"])[/COLOR]
    [COLOR="Blue"]END[/COLOR] [COLOR="Blue"]IF[/COLOR]
    
    [COLOR="Silver"]' Let's add a record:[/COLOR]
    [COLOR="Black"]Fld.Age[/COLOR]    [COLOR="Black"]=[/COLOR] [COLOR="Black"]76[/COLOR]
    [COLOR="Black"]Fld.Name[/COLOR]   [COLOR="Black"]=[/COLOR] [COLOR="DarkGreen"]"John Lennon"[/COLOR]
    [COLOR="Black"]Fld.gender[/COLOR] [COLOR="Black"]=[/COLOR] [COLOR="Red"]%MALE[/COLOR]
    [COLOR="Blue"]CALL[/COLOR] [COLOR="Blue"]MYSQL_INSERT_UDT[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld[/COLOR][COLOR="Black"])[/COLOR]
    
    [COLOR="Silver"]' We clear our variable.[/COLOR]
    [COLOR="Blue"]RESET[/COLOR] [COLOR="Black"]Fld[/COLOR]
    
    [COLOR="Silver"]' And we fill it again from database.[/COLOR]
    [COLOR="Blue"]MYSQL_FILL_UDT[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld[/COLOR][COLOR="Black"],[/COLOR] [COLOR="DarkGreen"]"where name='John Lennon'"[/COLOR][COLOR="Black"])[/COLOR]
    
    [COLOR="Silver"]' Finally we present it on screen.[/COLOR]
    [COLOR="Blue"]PRINTBR[/COLOR] [COLOR="Blue"]FORMAT$[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld.Age[/COLOR][COLOR="Black"])[/COLOR]
    [COLOR="Blue"]PRINTBR[/COLOR] [COLOR="Blue"]TRIM$[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld.Name[/COLOR][COLOR="Black"])[/COLOR]
    [COLOR="Blue"]PRINTBR[/COLOR] [COLOR="Blue"]CHOOSE$[/COLOR][COLOR="Black"]([/COLOR][COLOR="Black"]Fld.gender[/COLOR][COLOR="Black"],[/COLOR] [COLOR="DarkGreen"]"Male"[/COLOR][COLOR="Black"],[/COLOR] [COLOR="DarkGreen"]"Female"[/COLOR][COLOR="Black"])[/COLOR]
               
    
    [COLOR="Blue"]END[/COLOR] [COLOR="Blue"]FUNCTION[/COLOR][/B][/FONT]
    www.patreon.com/pluribasic

  • #2
    I forgot, here is the link for it working:

    www.patreon.com/pluribasic

    Comment

    Working...
    X