# Example: Database Access

ns_register_proc GET /demo/movies getMovies

proc getMovies {} {

set page “<html><body>\nCurrent Movies:\n”

set db [ns_db gethandle moviedb]

set row [ns_db select $db “select * from movies”]

while {[ns_db getrow $db $row]} {

append page “[ns_set get $row movie]<br>\n”

}

append page “</body></html>”

ns_set free $row

ns_db releasehandle $db

ns_return 200 text/html $page

}

- ## ns_db can be used to access an SQL database:

Previous slide | Next slide | Back to first slide | View graphic version