Re: uniqid() function



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,

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.
Why do you not use the autoincrement featuer of the Database ?
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
.



Relevant Pages

  • Fastest way to Copy DB + Keys,Constraints to another server
    ... What would be the fastest way to copy a SQL Server 2005 database and its data ... to another server including keys and constraints, ...
    (microsoft.public.sqlserver.programming)
  • Create SharePoint Portal failed.
    ... One mentioned ensuring that SQL Server uses a case ... 13:55:40 Service database server is 'USDC-JOHRIV'. ... Update dbo.propertylist set DisplayName = N'Last name' ...
    (microsoft.public.sharepoint.portalserver)
  • Re: ADO Connection Timeout
    ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)
  • Web Developers - Happy Hearts And HDTV! - Lockergnome
    ... Certificate on your MSIIS Web server. ... getting data from a database is only half the problem. ... Zend recently started a series about building rock solid code in PHP. ... which provides bulk database conversion. ...
    (freebsd-questions)
  • Re: TNS could not resolve the connect identifier
    ... This database resides on Machine A. ... The Web server is running on Machine B. ... Using tnsping is not as good as using a real connection such as via ... client (note that this is terminology that appears in the 10g R2 ...
    (comp.databases.oracle.server)