• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session database not working, using cookies does

#1
[eluser]RJ[/eluser]
Hello,

I can't figure out why CI is not loading the default session cookie. Below is from my error log.

Quote:DEBUG - 2009-05-12 17:54:25 --> Database Driver Class Initialized
DEBUG - 2009-05-12 17:54:25 --> Session Class Initialized
DEBUG - 2009-05-12 17:54:25 --> Helper loaded: string_helper
DEBUG - 2009-05-12 17:54:25 --> Encrypt Class Initialized

// ERROR
DEBUG - 2009-05-12 17:54:25 --> A session cookie was not found.
DEBUG - 2009-05-12 17:54:25 --> DB Transaction Failure
ERROR - 2009-05-12 17:54:25 --> Query error: Field 'user_data' doesn't have a default value
DEBUG - 2009-05-12 17:54:25 --> Language file loaded: language/english/db_lang.php

Here is my onscreen error:
Quote:Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO `fw_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('d3dd4efd8ee68a6218696b66aaf9fa86', '173.15.201.122', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;', 1242136465)

I did recently switch to using database rather than cookies, and worked fine until this error appeared. any ideas why? the field "user_data" is not specified by me... NOTE: system works without database enabled now.

#2
[eluser]TheFuzzy0ne[/eluser]
Have you extended the session class at all?

Please post your database schema.

Here's mine:

Code:
CREATE TABLE `ci_sessions` (
  `session_id` varchar(40) collate utf8_unicode_ci NOT NULL default '0',
  `ip_address` varchar(16) collate utf8_unicode_ci NOT NULL default '0',
  `user_agent` varchar(50) collate utf8_unicode_ci NOT NULL,
  `last_activity` int(10) unsigned NOT NULL default '0',
  `user_data` text collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Does yours differ in any way? There is no default set for the userdata, but mine seems to work without that. Which database and storage engine are you running?

#3
[eluser]RJ[/eluser]
differs only slightly. when i intially switched to db, had no problems and there are values stored in the db. now it wants to act up!

screen shot of db layout attached.

using mysql

#4
[eluser]TheFuzzy0ne[/eluser]
I doubt the collation should make any difference, but it may be worth checking out. If it's imperative you use your existing collation, then you could probably just add a default value for that field, but I can't see why you should need to. It is strange that it worked, but then stopped working.

Also, I'm still wondering whether or not you've extended the session class?

#5
[eluser]RJ[/eluser]
damn, change coll to UTF8, nothing, same error. what i notice is the error occurs before even my first controller; and after the language file is loaded.

Checking in the session library of CI I found this may be the root of error
Code:
$row = $query->row();
            if (isset($row->user_data) AND $row->user_data != '')
            {
                $custom_data = $this->_unserialize($row->user_data);

                if (is_array($custom_data))
                {
                    foreach ($custom_data as $key => $val)
                    {
                        $session[$key] = $val;
                    }
                }
            }

Now $this->userdata is set at the top and referenced through out, however the first instance of user_data is in the code above line2, line 217 in Session.php. any idea what triggers that and may be causing the error?

#6
[eluser]TheFuzzy0ne[/eluser]
I'm sorry, but I don't understand what you mean.

#7
[eluser]RJ[/eluser]
$this->userdata is set throughout the Session.php library. user_data or more specifically $row->user_data is initially declared on like 217. My error say there is no default value for user_data.

trying to reverse engineer the problem back to it's source; but i'm stuck here.

#8
[eluser]TheFuzzy0ne[/eluser]
What you are receiving, is a database error, and the database appears to be complaining that the userdata field has no default value (as the session class doesn't insert any userdata when the session is first created).

I can only conclude that dropping the table, and recreating it from the schema I posted. It just doesn't make sense why else it would throw that error for you, and no-one else.

#9
[eluser]RJ[/eluser]
This is my config settings
Code:
$config['sess_cookie_name']        = 'fw_session';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'fw_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;

Same error # on new database using your setup (changed ci to fw)
Quote:Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO `fw_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('a6715fb2be98abdff84db8656427ca55', '173.15.201.122', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;', 1242152041)

any thoughts?

#10
[eluser]TheFuzzy0ne[/eluser]
It's starting to sound like your MySQL server may have one of the strict modes enabled - http://dev.mysql.com/doc/refman/5.0/en/s...ans_tables


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.