Web Site Sample
CobolScript can access MySQL server using a Node.js module, and listing databases, tables and columns in dynamic web pages. It uses Twitter bootstrap, and SimpleWeb middleware layer.
Then, execute at command line:
This command installs the
simpleweb modules, according to the dependecies described in
You must create a database
cobolscriptwebsite in your MySQL database, and then execute the commands at
commands defines the tables and initial data to be used by the sample.
With the command line:
Server started, listening at port 8000
The program connects to the MySQL server at localhost and list its database. The server must be running.
In the pages, the code
perform require using "mysql" giving mysql.
local options. move object to options. move "root" to user in options. move "" to password in options. move "cobolscriptwebsite" to database options. local connection. perform createConnection in mysql using options giving connection.
opens the connection.
perform query in connection using "select Id, Name, Address, Notes from customers order by Id" showcustomers. showcustomers section using err, rows, fields. * ....
showcustomers as a callback to asynchronous method
The callback accept three parameters:
When the sql is an update command:
perform query in connection using "insert customers set Name = ?, Address = ?, Notes = ?" datavalues showcustomers.
then the callback receives two parameters:
datavalues parameters is an array, with the values to be passed to
See node-sql for more detailed information.