Re: uniqid() function
- From: Daniel <daniel@xxxxxxxxxxxxx>
- Date: Mon, 18 May 2009 14:39:51 -0500
On Mon, 18 May 2009 10:14:50 +0200, "j.keßler"
<mail@xxxxxxxxxxxxxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Lan Mind wrote:
Hello everybody,Why do you not use the autoincrement featuer of the Database ?
I am considering using PHP's uniqid() function to generate IDs for
records in a database. Is it possible for two IDs to have the same
value if the PHP script is on only one server? Will the server give
the same ID based upon current microtime to two users that use the PHP
script simultaneously?
I ask this because I have only one hosting account and PHP.net speaks
of generating identifiers simultaneously on SEVERAL HOSTS here in the
prefix parameter section:
http://us3.php.net/manual/en/function.uniqid.php
I don't know very well how servers work and how they handle
simultaneous requests. Thank you for your time.
with this field every new row will get its uniqe id.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkoRGPoACgkQE++2Zdc7Etd1RwCfYJnys58CUFPQdFAZNLrHobFB
7E8AniwfVFoFcLt7QKDNfcIhvpv+bbH6
=QTIl
-----END PGP SIGNATURE-----
There are some advantages in generating the id youself
- It is cross database - one thing is to get a unique id from oracle,
different is in mysql and ms sql server.
- Sometimes you need to generate an entire data structure with
referential integrity and pass it to the data access object or to the
business tier to be operated wthin only one transaction. Generating
the keys yourself makes the stuff very easy, otherwise you first have
to insert the master, then get the generated key, then update the
dependent value objects with the value, then operate them as well etc.
- In these times you might need to actually create the data structure
outside the server - for example you write a SOAP web service in php
and you need to persist a complex data structure that you created on a
client application. So you generate all the keys outside your server
and then call the web service. This is not doable if you stick to the
db generated key.
Disadvantages:
- possible collisions - although personally never had the issue
- the user generated keys are usually longer than the ones generated
by the dbs - for ex. I prefer to generate 32 bytes keys. So that will
occupy some more disk space. Once you are willing to get over that, it
is fine
Daniel
.
- References:
- uniqid() function
- From: Lan Mind
- Re: uniqid() function
- From: "j.keßler"
- uniqid() function
- Prev by Date: Re: PHP select date question
- Next by Date: Re: uniqid() function
- Previous by thread: Re: uniqid() function
- Next by thread: Re: uniqid() function
- Index(es):
Relevant Pages
|