Re: Unique Object Instance ID..?
| From: | Colin Guthrie | Date: | Sat, 10 Jan 2009 23:46:04 +0000 |
| Subject: | Re: Unique Object Instance ID..? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-285986@lists.php.net to get a copy of this message | ||
'Twas brillig, and Nathan Rixham at 10/01/09 23:31 did gyre and gimble:
all I need is a completely unique id for each object instance that can never be repeated at any time, even in a multiserver environment (and without using any kind of incremented value from a db table or third party app) thoughts, ideas, recommendations?While it's not guaranteed to be unique the general technique used in these situations is to use a UUID. The chances of a clash are slim (2x10^38 ish combinations). You can generate a uuid via mysql "SELECT UUID()" or via the PHP Pecl extension php-uuid. The other way of doing it would be to insert a row into a database row with an auto-increment field and use the value of that auto-incrment field as your identifier (SELECT LAST_INSERT_ID() in mysql or via the db layers API). HTHs Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/]