Reputation: 46
Ive already finish creating the shopping cart in codeigniter using shopping cart class. but the data was stored in session in array then i want to store the session array in database user_ordered. with userid, productid, qty. or other values.
Upvotes: 1
Views: 1765
Reputation: 2063
You can easily store your Session Array in the database using codeIgniter. In order to store sessions, you must first create a database table for this purpose. Here is the basic prototype (for MySQL) required by the session class:
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
By default the table is called ci_sessions
, but you can name it anything you want as long as you update the application/config/config.php
file so that it contains the name you have chosen. Once you have created your database table you can enable the database option in your config.php
file as follows:
$config['sess_use_database'] = TRUE;
Once enabled, the Session class will store session data in the DB.
Make sure you've specified the table name in your config file as well:
$config['sess_table_name'] = 'ci_sessions';
The same instructions can be found in the codeigniter documentation.
Upvotes: 1