[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re[2]: Duplicate entry
In article <13144553197.20010628041442@xxxxxxxxxxxxxxx>,
Werner Stuerenburg <ws@xxxxxxxxxxxxxxx> writes:
> function getSessionID(){
> global $sessionID;
> if ($sessionID) return;
> $test = 1;
> //start, if we have no sessionID (i.e. from a Cookie)
> $db = newDB($db);// get a PHPLIB class instance
> while($test){
> mt_srand((double)microtime()*1000000);//seed
> $sessionID = substr(md5(uniqid(mt_rand())), 0, 4);
> //generate a random key, md5 and chop it
> $q = "SELECT * FROM sessData
> WHERE sid = '$sessionID'";
> $db->query($q);//se if we have it already
> $test = $db->nf();
> if (!$test){//no, grab it
> $datum = date("Y-m-d H:i:s");
> $q = "INSERT INTO sessData
> (sid, varsVal, datum)
> VALUES ('$sessionID', 'dummySession', '$datum')";
> $db->query($q);
> if ($db->Errno) getSessionID();
> //if error, try again, just in case
> }//else it is taken, get next
> }
> }
Doing a SELECT and then an INSERT without LOCK TABLE doesn't seem very
robust to me. Why don't you simply try to INSERT and if it fails due
to a duplicate sid generate another session ID?
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <mysql-thread77900@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
This mailing list archive is a service of Copilot Consulting.