[phplib] primary-key db problem and question From: Lindsay Haisley (fmouse <email protected>)
Date: 07/15/01

Please excuse the post in English. Meine Deutsch ist nicht gut!

I just moved an an application for a client between systems, both running
Red Hat Linux with apache, php and mysql. Software versions on the two
systems are;

        Old System New System
PHP 3.x 4.x
MySQL 3.22.32 3.23.22-beta
phplib 6.1 6.1

We're running an administrative system which I wrote which uses session
management and authentication, among other features of phplib. After moving
the software to the new system I noted that I was usually getting an error
out of MySQL regarding an attempt to insert a new record into the
active_sessions database with a duplicate key. This wasn't a problem on the
old installation.

Further investigation indicated that the problem was occurring in the
$sess->freeze() method. If two calls to freeze are made within the same 1
second window (as defined by $now), and the session data hasn't changed, all
data in the update query will be identical to the data already in the table
and the subsequent call to $db->affected_rows() will return 0. The
subsequent conditional checks this return and if it's 0, an attempt is
made to insert a new record into active_sessions. If a record already
exists for the same name and sid (primary key), MySQL will throw out an
error which is echoed by php to the browser window. I had to insert code
into session.inc to specifically check for the existence of a session record
for the current session if $db->affected_rows() returns 0.

I note that similar code exists in phplib-7.2b, although it's been moved to
ct_* files.

I'm puzzled by this error. We've been using this same code on the old
system for some time, and have never seen this error, which logically should
have occurred. Is there a system setting somewhere which supresses such
errors in php? It looks like a bug in phplib, which is basing a record
existence check on the results (affected_rows) of an operation (update)
which can be 0 under two different conditions, only one of which is
nonexistence of the record. In spite of this, it's been working flawlessly
until we moved the software to a new server.

Am I missing something here? I've solved the problem, at the expense of a
very small loss of speed, but I'd like to know why we haven't run across the
problem previously.

-- 
Lindsay Haisley       | "Everything works    |     PGP public key
FMP Computer Services |       if you let it" |      available at
512-259-1190          |    (The Roadie)      | <http://www.fmp.com/pubkeys>
http://www.fmp.com    |                      |

-- Abbestellen mit Mail an: phplib-unsubscribe <email protected> Kommandoliste mit Mail an: phplib-help <email protected>