From rdyes@monroehosp.org Thu Sep 14 13:53:07 2006 X-Original-To: pgsql-php-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 034009FA15C for ; Thu, 14 Sep 2006 10:53:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 31325-05 for ; Thu, 14 Sep 2006 10:52:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from emailserver.monroehosp.org (emailserver.monroehosp.org [199.248.251.5]) by postgresql.org (Postfix) with ESMTP id 35BFD9FA0C4 for ; Thu, 14 Sep 2006 10:52:55 -0300 (ADT) Received: from vams.monroehosp.org (unknown [172.31.5.102]) by emailserver.monroehosp.org (Postfix) with SMTP id 238AEBC6F for ; Thu, 14 Sep 2006 09:52:51 -0400 (EDT) Received: from [127.0.0.1] (unknown [199.248.251.30]) by emailserver.monroehosp.org (Postfix) with ESMTP id 98835BC6F for ; Thu, 14 Sep 2006 09:52:50 -0400 (EDT) Message-ID: <45095EB1.50707@monroehosp.org> Date: Thu, 14 Sep 2006 09:52:49 -0400 From: Richmond Dyes Reply-To: Richmond.Dyes@monroehosp.org Organization: Monroe Community Hospital(Director of Information Systems) User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: Having problems with user defined sessions using postgresql as my session manager Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.383 tagged_above=0 required=5 tests=AWL, HTML_40_50, HTML_MESSAGE, HTML_TITLE_EMPTY, MIME_HTML_ONLY X-Spam-Level: X-Archive-Number: 200609/2 X-Sequence-Number: 3599 I have written user defined session management library in php using postgresql as my session repository.  When I let my session timeout on my browser I get the below errors on my screen.

   Warning: pg_query(): Query failed: ERROR: duplicate key violates unique constraint "li_session_pkey" in /var/www/html/liberty/includes/session.php on line 31

Fatal error: Call to undefined function: pg_error() in /var/www/html/liberty/includes/session.php on line 31

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

The problem is in the write function of my library. Here it is:

function pg_session_write($sid, $val) {
    $life = get_cfg_var("session.gc_maxlifetime");
    $exp = time() + $life;
    $selQ = "SELECT sidid FROM li_session
    WHERE sidid = '$sid' AND exptime >". time();
    $selR= pg_query($selQ)or die("It didn't work:". pg_error());
     if(pg_num_rows($selR)) {
        $sesupQ ="UPDATE li_session SET
        exptime = '$exp', vidval = '$val'
        WHERE
        sidid = '$sid' and exptime >". time();
        $sesupR=pg_query($sesupQ) or die("It didn't work:". pg_error());
    } else {
     $sesinQ = "INSERT INTO li_session
    VALUES('$sid', '$val', '$exp')";
    $sesinR= pg_query($sesinQ) or die("It didn't work:". pg_error());   
    }
}
From erik@myemma.com Thu Sep 14 15:10:58 2006 X-Original-To: pgsql-php-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 4707F9FB1E0 for ; Thu, 14 Sep 2006 12:10:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 98138-05 for ; Thu, 14 Sep 2006 15:10:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from myemma.com (db1.e2ma.net [66.179.147.163]) by postgresql.org (Postfix) with ESMTP id 40D909FA0FC for ; Thu, 14 Sep 2006 12:10:51 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by myemma.com (Postfix) with ESMTP id 907C123CF0; Thu, 14 Sep 2006 10:10:50 -0500 (CDT) Received: from myemma.com ([127.0.0.1]) by localhost (velma [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16106-08; Thu, 14 Sep 2006 10:10:50 -0500 (CDT) Received: from [10.0.23.37] (unknown [205.241.239.26]) by myemma.com (Postfix) with ESMTP id E9E0023CED; Thu, 14 Sep 2006 10:10:49 -0500 (CDT) Message-ID: <450970F3.1070507@myemma.com> Date: Thu, 14 Sep 2006 10:10:43 -0500 From: Erik Jones User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 To: Richmond.Dyes@monroehosp.org Cc: pgsql-php@postgresql.org Subject: Re: Having problems with user defined sessions using postgresql References: <45095EB1.50707@monroehosp.org> In-Reply-To: <45095EB1.50707@monroehosp.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at myemma.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.133 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/3 X-Sequence-Number: 3600 Ok, 1. PHPs postgres lib doesn't have a pg_error() function. You want pg_last_error(). 2. Are you using the sid as li_session's primary key? If so, before you create a new session with an already existing sid, you will need to delete the old sid entry before inserting a new one with the same sid. Richmond Dyes wrote: > I have written user defined session management library in php using > postgresql as my session repository. When I let my session timeout on > my browser I get the below errors on my screen. > > *Warning*: pg_query(): Query failed: ERROR: duplicate key violates > unique constraint "li_session_pkey" in > */var/www/html/liberty/includes/session.php* on line *31* > > *Fatal error*: Call to undefined function: pg_error() in > */var/www/html/liberty/includes/session.php* on line *31* > > *Warning*: Unknown(): A session is active. You cannot change the > session module's ini settings at this time. in *Unknown* on line *0 > > The problem is in the write function of my library. Here it is: > > function pg_session_write($sid, $val) { > $life = get_cfg_var("session.gc_maxlifetime"); > $exp = time() + $life; > $selQ = "SELECT sidid FROM li_session > WHERE sidid = '$sid' AND exptime >". time(); > $selR= pg_query($selQ)or die("It didn't work:". pg_error()); > if(pg_num_rows($selR)) { > $sesupQ ="UPDATE li_session SET > exptime = '$exp', vidval = '$val' > WHERE > sidid = '$sid' and exptime >". time(); > $sesupR=pg_query($sesupQ) or die("It didn't work:". pg_error()); > } else { > $sesinQ = "INSERT INTO li_session > VALUES('$sid', '$val', '$exp')"; > $sesinR= pg_query($sesinQ) or die("It didn't work:". pg_error()); > } > } > * -- erik jones software development emma(r)