I recently developed an extension that enables the Rebol 3 language to connect to MySQL database. You can find it here:
https://github.com/kronwiz/r3-mysql
Here I describe it briefly, but you can find all the details following the link above.
To access a MySQL database you have to create the database object:
db: make mysql/database []
Then you connect to the database:
db/connect "localhost" "test" "test" "test"
To execute queries there's the execute method:
db/execute "select * from addressbook"
If the query was a select you have to fetch the result set. You fetch it a row at a time like this:
row: db/fetch-row
The row is a series of field name, field value. For example, from the test database:
["userid" 1 "firstname" "A" "lastname" "B" "phone" "123456" "address" "route 66" "city" "C" "zip" "9876" "state" "Nowhere" "created" 27-May-2014/9:08:50 "mod_date" 27-May-2014 "mod_time" 9:08:50 "height" 12.754638 "width" "12.7546"]
This plays well with select so that to retrieve a field value you can do:
address: select row "address"
All statements (delete, insert, ecc.) are executed through the execute method. The execute method has a params refinement that lets you pass values as parameters after the query string. For example:
db/execute/params "insert into addressbook values( ?, 'First', 'Last', '333.123.444', ?, 'non so', ?, 'Italy', ?, ?, ?, ?, '23.16432' )" [ none "via di qua" 4563 23-Jan-2012/13:55 23-Jan-2012 13:55 5634.333 ]
If you need some help on Rebol or my extension you can connect to the Rebol and Red chat.
https://github.com/kronwiz/r3-mysql
Here I describe it briefly, but you can find all the details following the link above.
To access a MySQL database you have to create the database object:
db: make mysql/database []
Then you connect to the database:
db/connect "localhost" "test" "test" "test"
To execute queries there's the execute method:
db/execute "select * from addressbook"
If the query was a select you have to fetch the result set. You fetch it a row at a time like this:
row: db/fetch-row
The row is a series of field name, field value. For example, from the test database:
["userid" 1 "firstname" "A" "lastname" "B" "phone" "123456" "address" "route 66" "city" "C" "zip" "9876" "state" "Nowhere" "created" 27-May-2014/9:08:50 "mod_date" 27-May-2014 "mod_time" 9:08:50 "height" 12.754638 "width" "12.7546"]
This plays well with select so that to retrieve a field value you can do:
address: select row "address"
All statements (delete, insert, ecc.) are executed through the execute method. The execute method has a params refinement that lets you pass values as parameters after the query string. For example:
db/execute/params "insert into addressbook values( ?, 'First', 'Last', '333.123.444', ?, 'non so', ?, 'Italy', ?, ?, ?, ?, '23.16432' )" [ none "via di qua" 4563 23-Jan-2012/13:55 23-Jan-2012 13:55 5634.333 ]
If you need some help on Rebol or my extension you can connect to the Rebol and Red chat.
Comments
Post a Comment