Database Reference
In-Depth Information
"database_manager" => CGI : :Session :: MySQLStore ,
"db.host" => "localhost" ,
"db.user" => "cbuser" ,
"db.pass" => "cbpass" ,
"db.name" => "cookbook" ,
"db.table" => "ruby_session" ,
"db.hold_conn" => 1
)
The db. xxx parameters used in that code tell mysql-session how to connect to the
server, as well as the database and table for session records:
db.host
The host where the MySQL server is running.
db.user , db.pass
The username and password of the MySQL account to use.
db.name , db.table
The database and table names for the session table.
db.hold_conn
By default, mysql-session opens and closes a connection each time it needs to send
a statement to the MySQL server. If the db.hold_conn parameter is 1, mysql-
session opens the connection only once and holds it open until the session ends.
Another way to create a session is to pass the handle for an already open database
connection(represented using dbh ):
cgi = CGI . new ( "html4" )
sess_id = cgi . cookies [ "RUBYSESSID" ]
session = CGI : :Session . new (
cgi ,
"session_key" => "RUBYSESSID" ,
"database_manager" => CGI : :Session :: MySQLStore ,
"db.dbh" => dbh ,
"db.name" => "cookbook" ,
"db.table" => "ruby_session"
)
In this case, the db.host , db.user , db.pass , and db.hold_conn parameters are not used.
Close the connection yourself when you're done with it.
Whichever way you create the session, its ID is available while it is open as the ses
sion.session_id attribute.
To close or destroy the session, invoke the close or delete method of the session object,
respectively.
The session manager stores data as key/value pairs, using strings for the values. It does
not know the types of the values that you store. I find the following strategy useful for
dealing with type-conversion issues:
Search WWH ::




Custom Search