简体   繁体   中英

PostgreSQL and Codeigniter Sessions issues

I am trying to store the user data into database in PgSQL with Codeigniter as framework.

Now I created a table ci_sessions:

  CREATE TABLE IF NOT EXISTS ci_sessions (
  session_id varchar(40) NOT NULL DEFAULT '0',
  ip_address varchar(45) NOT NULL DEFAULT '0',
  user_agent varchar(120) NOT NULL,
  last_activity int check (last_activity > 0) NOT NULL DEFAULT '0',
  user_data text NOT NULL,
  PRIMARY KEY (session_id)
) ;

CREATE INDEX last_activity_idx ON ci_sessions (last_activity);

In my config.php these are my parameters:

$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;

In mysql these were enough to store the userdata into database.

But for PgSql I am getting numbers of errors:

  • session_id was unknow to the db driver asked me to change it to id
  • user_agent was also unknown, so I had to remove it from database
  • last_activity, was also unknown
  • Similarly for the driver the user_data should be only data as field.

I had to do many changes for it to work, still when I did as it asked for it did not store information regarding the userdata such as browser, user agent etc.

My error looked like this :

 Severity: Warning

Message: pg_query(): Query failed: ERROR: column "data" does not exist LINE 1: SELECT "data" ^

Filename: postgre/postgre_driver.php

Line Number: 242

Backtrace:

File: C:\\wamp\\www\\project\\application\\core\\MY_Controller.php Line: 13 Function: __construct

File: C:\\wamp\\www\\project\\application\\libraries\\Admin_Controller.php Line: 10 Function: __construct

File: C:\\wamp\\www\\project\\application\\controllers\\admin\\Dashboard.php Line: 11 Function: __construct

File: C:\\wamp\\www\\project\\index.php Line: 316 Function: require_once

CREATE TABLE "ci_sessions" (
    "id" varchar(128) NOT NULL,
    "ip_address" varchar(45) NOT NULL,
    "timestamp" bigint DEFAULT 0 NOT NULL,
    "data" text DEFAULT '' NOT NULL
);

CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp");

According at the online docs this is the table that you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM