dynamic table creation #sessions

This commit is contained in:
Claude 2012-04-14 20:06:22 +02:00
parent 51f58c5710
commit db86e84e72
3 changed files with 38 additions and 87 deletions

View File

@ -25,6 +25,39 @@ class Main extends CI_Controller
{
parent::__construct();
$this->load->model('languages');
if (!$this->db->table_exists('ci_sessions'))
{
$this->load->dbforge();
$fields = array(
'session_id' => array(
'type' => 'VARCHAR',
'constraint' => 40,
'default' => 0,
) ,
'ip_address' => array(
'type' => 'VARCHAR',
'constraint' => 16,
'default' => 0,
) ,
'user_agent' => array(
'type' => 'VARCHAR',
'constraint' => 50,
) ,
'last_activity' => array(
'type' => 'INT',
'constraint' => 10,
'unsigned' => TRUE,
'default' => 0,
) ,
'session_data' => array(
'type' => 'TEXT',
) ,
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('session_id', true);
$this->dbforge->create_table('ci_sessions', true);
}
}
function _form_prep($lang = 'php', $title = '', $paste = '', $reply = false)

View File

@ -39,7 +39,10 @@ class DB_Session {
$this->object =& get_instance();
log_message('debug', "Session Class Initialized (db)");
$this->sess_run();
if($this->object->db->table_exists('ci_sessions')) {
$this->sess_run();
}
}
// --------------------------------------------------------------------
@ -506,4 +509,4 @@ PRIMARY KEY (session_id)
);
*/
?>
?>

View File

@ -21,91 +21,6 @@ SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- --------------------------------------------------------
--
-- Table structure for table `ci_sessions`
--
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`session_id` varchar(40) NOT NULL default '0',
`ip_address` varchar(16) NOT NULL default '0',
`user_agent` varchar(50) NOT NULL,
`last_activity` int(10) unsigned NOT NULL default '0',
`session_data` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `languages`
--
CREATE TABLE IF NOT EXISTS `languages` (
`code` varchar(12) character set utf8 collate utf8_unicode_ci NOT NULL,
`description` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `languages`
--
INSERT INTO `languages` (`code`, `description`) VALUES
('c', 'C'),
('css', 'CSS'),
('cpp', 'C++'),
('html4strict', 'HTML (4 Strict)'),
('java', 'Java'),
('perl', 'Perl'),
('php', 'PHP'),
('python', 'Python'),
('ruby', 'Ruby'),
('text', 'Plain Text'),
('asm', 'ASM (Nasm Syntax)'),
('xhtml', 'XHTML'),
('actionscript', 'Actionscript'),
('ada', 'ADA'),
('apache', 'Apache Log'),
('applescript', 'AppleScript'),
('autoit', 'AutoIT'),
('bash', 'Bash'),
('bptzbasic', 'BptzBasic'),
('c_mac', 'C for Macs'),
('csharp', 'C#'),
('ColdFusion', 'coldfusion'),
('delphi', 'Delphi'),
('eiffel', 'Eiffel'),
('fortran', 'Fortran'),
('freebasic', 'FreeBasic'),
('gml', 'GML'),
('groovy', 'Groovy'),
('inno', 'Inno'),
('java5', 'Java 5'),
('javascript', 'Javascript'),
('latex', 'LaTeX'),
('mirc', 'mIRC'),
('mysql', 'MySQL'),
('nsis', 'NSIS'),
('objc', 'Objective C'),
('ocaml', 'OCaml'),
('oobas', 'OpenOffice BASIC'),
('orcale8', 'Orcale 8 SQL'),
('pascal', 'Pascal'),
('plsql', 'PL/SQL'),
('qbasic', 'Q(uick)BASIC'),
('robots', 'robots.txt'),
('scheme', 'Scheme'),
('sdlbasic', 'SDLBasic'),
('smalltalk', 'Smalltalk'),
('smarty', 'Smarty'),
('sql', 'SQL'),
('tcl', 'TCL'),
('vbnet', 'VB.NET'),
('vb', 'Visual BASIC'),
('winbatch', 'Winbatch'),
('xml', 'XML'),
('z80', 'z80 ASM');
--
-- Table structure for table `pastes`
--