Return to index

db functions

db_close(handle)

top

Closes the database connection.

Example:

# Example for db_close
var db=db_init("mydb")
db_close(db)


handle = db_init(string)

top

Returns a database connection handle, with a default schema of string based on

[#SOL]inbound environmental variables. (ZA_DB_HOST, ZA_DB_ENGINE, ZA_DB_PORT, ZA_DB_USER, ZA_DB_PASS.)

[#SOL]Only 'mysql' is currently supported as an engine type.

Example:

set_env("ZA_DB_ENGINE","mysql")
set_env("ZA_DB_HOST","localhost")
set_env("ZA_DB_PORT","3306")
set_env("ZA_DB_USER","zatester")
set_env("ZA_DB_PASS","notarealpassword")

dbh=db_init("mysql")
q=db_query(dbh,"select * from user;","|")

flds=split(q[0],"|")

foreach f in flds
    print "<# Example for db_close
var db=db_init(&#34;mydb&#34;)
db_close(db)
> "
endfor
println

`
output will be similar to this:
<%> <test_user> <*NOTTHEREALSTRING> <Y> <Y> <Y> <Y> <Y> <Y> <N> <N> <N> <N> <N> <N> <Y> <N> <N> <N> <Y> <Y> <N> <N> <N> \
<N> <N> <N> <N> <N> <N> <N> <N> <N> <> <> <> <> <0> <0> <0> <0> <> <> <N> <N> <> <0.000000>
`


q=db_query(dbh, "describe `mysql`.`user`;","|")

widths=[30,30,10,10,20,20]
foreach r in q
    cols=split(r,"|")
    foreach c in cols
        w=widths[key_c]+4
        print format("%{w}s",c)
    endfor
    println
endfor

`output will be like...
                              Host                          char(60)            NO           PRI                                                
                              User                          char(80)            NO           PRI                                                
                          Password                          char(41)            NO                                                              
                       Select_priv                     enum('N','Y')            NO                                     N                        
                       Insert_priv                     enum('N','Y')            NO                                     N                        
                       Update_priv                     enum('N','Y')            NO                                     N        
.
.
.
`

db_close(dbh)

# you aren't going to be doing anything complicated with this. it's just for simple queries.
# there is no support for things like transactions, multi-statement queries or prepared statements.


string = db_query(handle,query[,options])

top

Database query with optional map configuration. Options: map(.params [values], .separator "|", .timeout 30, .fetch_size 1000, .limit 100, .format "string|json|csv|tsv|table|map|array|yaml|xml|jsonl")