2007. 03. 23, péntek keltezéssel 08.13-kor Robert Cummings ezt írta: > On Fri, 2007-03-23 at 09:15 +0100, Németh Zoltán wrote: > > > // method 2 > > $time = microtime(TRUE); > > for ($i = 1; $i <= 5000; $i++) { > > $done = FALSE; > > while (!$done) { > > $id = md5((microtime(TRUE) * (rand(1,1000) / 100))); > > $sql = "INSERT INTO idtest (id,cnt) VALUES ('$id', $i)"; > > $result = mysql_query($sql); > > if ($result) { $done = TRUE; } > > } > > } > > $end = microtime(TRUE) - $time; > > echo "method 2 time: " . $end . "<br>"; > > One of the problems with the above style is that if the query fails for > some other reason (typo, no permissions, database temporarily > unavailable, etc) the code will run indefinitely (or until it gets > killed for too much time). That's a very dirty way to manage failed > inserts due to dupes. yes, of course. that's good only for this small test, not for real life use ;) for real use one should check mysql_errno end take action based on that greets Zoltán Németh > > Cheers, > Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php