Example of database connection using ns_db 0or1row

http://naviserver.sourceforge.net/ns_logobig.gif

MainHome Page Source Code Downloads API Documentation Mailing Lists Bugs Developers


ns_db 0or1row

Tcl example of database connection using ns_db 0or1row.

ns_register_proc GET /index.html db_test_0or1row

proc db_test_0or1row {} {
    set pool "main"
    set sql "select * from users where user_id = 1"
    set db [ns_db gethandle $pool]
    
    set row [ns_db 0or1row $db $sql]
    if {$row eq ""} {
        set html "No rows matched the query"
    } else {
        set html [ns_set array $row]
    }

    ns_db releasehandle $db

    ns_return 200 text/html $html
}