Welcome Guest, Not a member yet? Register   Sign In
Problem with Session tables
#1

Hello.

I just recently upgraded to the latest version of codeigniter.

I autoload the 'session' and 'database' class, but whenever i try to go to a new page i get the following error in Firebug:


A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET `last_activity` = 1442437198, `user_data` = 'a:3:{s:9:\"user_data\";s:0:\"\"' at line 1

UPDATE SET `last_activity` = 1442437198, `user_data` = 'a:3:{s:9:\"user_data\";s:0:\"\";s:7:\"user_id\";s:1:\"1\";s:6:\"f_name\";s:5:\"Geoff\";}' WHERE `session_id` = 'e9a5fd8078a00c79ae91b268283188a0'

Filename: libraries/Session.php

Line Number: 289

I CANNOT UNDERSTAND WHAT I AM DOING WRONG!

My database is configured as follows:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => '',
'hostname' => '166.62.32.126',
'username' => 'xxxx',
'password' => 'xxxx',
'database' => 'a_cfg',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE, // can't switch to TRUE with the new session sql tables.
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => TRUE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

In config.php, i have set:

$config['encryption_key'] = '123';

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

and my session table is

CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (id),
KEY `ci_sessions_timestamp` (`timestamp`) );


FOR SOME REASON, it appears the code is reverting to what the old ci_sessions table used to look like, and not only that there's an error in the SQL syntax.

I've been struggling with this all day any help is greatly appreciated.

Thanks
Reply
#2

(09-16-2015, 02:16 PM)gloosemore Wrote: ...

Filename: libraries/Session.php

...

There's an important note on the upgrade instructions page, step 1 that you didn't follow.
Reply
#3

What would that be i still can't figure that out.

application/config/libraries directory is empty, only file is index.html.

system/libraries/session/Session.php file exists, that file is capitalized. In the same directory is also session_driver.php and SessionHandlerInterface.php.

I keep getting the same error. I made sure the upgrade to 3.0.1 was done successfully by completely download the new version then adding selected directories and files from the old version to the new version. I copied and pasted the views, controllers, and public folders from the old site. For config files i just re-entered information directly into the new config files instead of copying the old config files which i understand are outdated.

Upon autoloading 'session', why would I get an error in SQL syntax, while it also appears its trying to insert data into the old version of ci_sessions table??

Error Number: 1064


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET `last_activity` = 1442496306, `user_data` = 'a:3:{s:9:\"user_data\";s:0:\"\"' at line 1

UPDATE SET `last_activity` = 1442496306, `user_data` = 'a:3:{s:9:\"user_data\";s:0:\"\";s:7:\"user_id\";s:1:\"1\";s:6:\"f_name\";s:5:\"Geoff\";}' WHERE `session_id` = '47511770dba0f8e475664805ef4fe9a0'

Filename: libraries/Session.php

Line Number: 289
Reply
#4

(09-17-2015, 05:23 AM)Narf Wrote:
(09-16-2015, 02:16 PM)gloosemore Wrote: ...

Filename: libraries/Session.php

...

There's an important note on the upgrade instructions page, step 1 that you didn't follow.

I seem to have solved this problem by switching to the newer syntax. Instead of writing

$array = array("user_id" => 1, "f_name" => "John");
$this->session->set_userdata($array);

I write

$this->session->user_id = 1;
$this->session->f_name = "John";

However, I'm having a different problem (i think its a problem). Although session variables seem to be stored successfully, my ci_sessions table is EMPTY WHEN USERS ARE LOGGED IN. For example, if i set the session variables shown above, the table still appears empty in phpMyAdmin.

Again, my database configuration is now:


Code:
$active_group = 'default';

$query_builder = TRUE;

$db['default'] = array(
    'dsn'    => '',
    'hostname' => '166.62.32.126',
    'username' => 'xxxx',
    'password' => 'xxxx',
    'database' => 'a_cfg',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);


And my session is set in config:


Code:
$config['encryption_key'] = '1234567891234567';


$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sess';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;


NOTE that i couldnt get the encryption library to work so i just made one up. Don't know if that is a factor.

Thanks for any help
Reply
#5

Narf is referring to this:
Quote:Replace all files and directories in your system/ directory and replace your index.php file. If any modifications were made to your index.php they will need to be made fresh in this new one.

Important

You have to delete the old system/ directory first and then put the new one in its place. A simple copy-paste may cause issues.

The part which starts with "Important" is in a big orange box on the page he linked, so he probably thought it would be pretty hard to miss, especially since I believe it was added specifically because people were having the same issue you're having if they didn't delete the old system directory or use a completely new system directory.
Reply
#6

(09-18-2015, 07:18 AM)mwhitney Wrote: Narf is referring to this:

Quote:Replace all files and directories in your system/ directory and replace your index.php file. If any modifications were made to your index.php they will need to be made fresh in this new one.

Important

You have to delete the old system/ directory first and then put the new one in its place. A simple copy-paste may cause issues.

The part which starts with "Important" is in a big orange box on the page he linked, so he probably thought it would be pretty hard to miss, especially since I believe it was added specifically because people were having the same issue you're having if they didn't delete the old system directory or use a completely new system directory.

***SOLVED****

problem was with the WAMP testing server. All the time i was focusing on my actual website directory used to upload to the testing server and not the testing server itself. Files weren't being overwritten when i uploaded to WAMP if they had identical names. I deleted everything on the testing server, then uploaded again and it seems to work fine.

Thanks for all your help
Reply
#7

(09-18-2015, 08:37 AM)gloosemore Wrote:
(09-18-2015, 07:18 AM)mwhitney Wrote: Narf is referring to this:


Quote:Replace all files and directories in your system/ directory and replace your index.php file. If any modifications were made to your index.php they will need to be made fresh in this new one.

Important

You have to delete the old system/ directory first and then put the new one in its place. A simple copy-paste may cause issues.

The part which starts with "Important" is in a big orange box on the page he linked, so he probably thought it would be pretty hard to miss, especially since I believe it was added specifically because people were having the same issue you're having if they didn't delete the old system directory or use a completely new system directory.

***SOLVED****

problem was with the WAMP testing server. All the time i was focusing on my actual website directory used to upload to the testing server and not the testing server itself. Files weren't being overwritten when i uploaded to WAMP if they had identical names. I deleted everything on the testing server, then uploaded again and it seems to work fine.

Thanks for all your help

They are being overwritten and that was never your problem. I told you that you've missed an important note, mwhitney even quoted it here for you and you're still ignoring it ...

The CI_Loader class looks for libraries/Library_name.php first and CI2 had the session library in libraries/Session.php, while CI3 has it in libraries/Session/Session.php. Your application was still using the v2 one because you didn't delete it but just copy-pasted the new files on top of the old ones.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB