note 95584 added to function.mysql-insert-id

From: Date: Mon, 11 Jan 2010 06:19:16 +0000
Subject: note 95584 added to function.mysql-insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-164837@lists.php.net to get a copy of this message
There is a lot of incorrect info here on "don't use AI" and "using max is equivalent". Then you have people improperly advising you to use psuedo-random numbers If you're really worried about the AI field not returning because of the inherent race conditions, just do a select statement based on the vars you just input. If your vars are not unique, DON'T use these psuedo-random numbers. When you have enough iterations, the probability that the one of these randoms becomes a duplicate gets pretty high. Instead, just use the unix timestamp. However, don't use UNIX_TIMESTAMP() in your query, because if you do, when you run your select statement right after, there's a possibility that you'll end up with a different timestamp. Since date() continues to count up during the execution of the script, simply store date(U) into a variable or definition. Then insert and select based on that. Assuming you're not using mysql procedures: <?php define(UNIX_TIMESTAMP, date('U')); $db->query("insert into table values('', 'a', 'b', 'c', 'd', '".UNIX_TIMESTAMP."'"); $res = $db->query("select id from table where a_col = 'a' and b_col = 'b' and c_col = 'c' and d_col = 'd' and temp_id = 'UNIX_TIMESTAMP'"); ... ?> ---- Server IP: 69.147.83.197 Probable Submitter: 68.48.113.33 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php Edit -- https://master.php.net/note/edit/95584 Del: integrated -- https://master.php.net/note/delete/95584/integrated Del: useless -- https://master.php.net/note/delete/95584/useless Del: bad code -- https://master.php.net/note/delete/95584/bad+code Del: spam -- https://master.php.net/note/delete/95584/spam Del: non-english -- https://master.php.net/note/delete/95584/non-english Del: in docs -- https://master.php.net/note/delete/95584/in+docs Del: other reasons-- https://master.php.net/note/delete/95584 Reject -- https://master.php.net/note/reject/95584 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164837) next »