Re: [PHP] Creating a unique index ID

2006-03-15 Thread Burhan

tedd wrote:

Hey all,

I've got a project where I'm taking form information from the user and
writing records to several tables in a MySQL database.

The problem I'm having is I need to write a unique number for the ID
column of the records.  Auto increment won't work because I could have
conflicts due to replication of the database servers.  Anyone have any
techique they use for creating unique ID field entries in a db table?

I was thinking maybe using a random 3 digit number and a unix timestamp?

Jeff


Jeff:

Look into getmypid() and uniqid() or combine the two.


How about using a DB abstraction layer that provides its own method of 
implementing sequences? Wouldn't this take away the auto_increment problem?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating a unique index ID

2006-03-13 Thread tedd

Hey all,

I've got a project where I'm taking form information from the user and
writing records to several tables in a MySQL database.

The problem I'm having is I need to write a unique number for the ID
column of the records.  Auto increment won't work because I could have
conflicts due to replication of the database servers.  Anyone have any
techique they use for creating unique ID field entries in a db table?

I was thinking maybe using a random 3 digit number and a unix timestamp?

Jeff


Jeff:

Look into getmypid() and uniqid() or combine the two.

tedd

--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating a unique index ID

2006-03-13 Thread Tim A. Yarbrough


-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 13, 2006 9:50 AM
To: Jeff
Cc: [EMAIL PROTECTED]; php-general@lists.php.net
Subject: Re: [PHP] Creating a unique index ID

Jeff wrote:
>>-Original Message-
>>From: Jared Williams [mailto:[EMAIL PROTECTED] 
>>Sent: Monday, March 13, 2006 10:16
>>To: 'Jeff'; php-general@lists.php.net
>>Subject: RE: [PHP] Creating a unique index ID
>>
>>
>> 
>>
>>
>>>Hey all,
>>>
>>>I've got a project where I'm taking form information from the
>>>user and writing records to several tables in a MySQL database.
>>>
>>>The problem I'm having is I need to write a unique number for
>>>the ID column of the records.  Auto increment won't work 
>>>because I could have conflicts due to replication of the 
>>>database servers.  Anyone have any techique they use for 
>>>creating unique ID field entries in a db table?
>>>
>>
>>Autoincrements can work in a replicated enviroment, lookup 
>>mysql settings auto_increment_increment & auto_increment_offset.
>>
>>Each server gets its own unique auto_increment_offset, and 
>>auto_increment_increment is set to the number of servers you have.
>>
>>Jared
>>
> 
> 
> Hmm, 
> 
> actually I'm using circular replication, so it's a bit different than
> one way replication.
> 
> A replicates to B which replicates to A.

isn't that called synchronization? not that it matters. :-)

> 
> I've looked at the MySQL docs and can't find anything on how to make
> Auto_Increment work in Circular Replication.

just a thought(tm):

it's probably considered hackish (don't know why) but how about setting
up a seperate server/instance-of MySQL whose ONLY job it is to provide
new ids,
and then configure each system to connect [remotely] to the
aforementioned
db whenever a new id is required... which will probably require some
rewriting if you normally use mysql_insert_id() after a query to
determine an
id (with my proposal you are forced to explicitly generate an id before
hand)


> 

Only problem with that is you start to negate the redundancy of the
mysql setup then.  Because you make everything dependant on that one
server so if it goes down then everything dies.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating a unique index ID

2006-03-13 Thread Tim A. Yarbrough
Using the auto_increment_offset will take care of this problem.  Because
say server A can be configured to use odd numbers and server B can be
configured to use even numbers.  You can also set this up in a more
complex fashion for the offsets if your running more then 2 servers.

-Original Message-
From: Jeff [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 13, 2006 9:41 AM
To: [EMAIL PROTECTED]; php-general@lists.php.net
Subject: RE: [PHP] Creating a unique index ID

> -Original Message-
> From: Jared Williams [mailto:[EMAIL PROTECTED] 
> Sent: Monday, March 13, 2006 10:16
> To: 'Jeff'; php-general@lists.php.net
> Subject: RE: [PHP] Creating a unique index ID
> 
> 
>  
> 
> > Hey all,
> > 
> > I've got a project where I'm taking form information from the
> > user and writing records to several tables in a MySQL database.
> > 
> > The problem I'm having is I need to write a unique number for
> > the ID column of the records.  Auto increment won't work 
> > because I could have conflicts due to replication of the 
> > database servers.  Anyone have any techique they use for 
> > creating unique ID field entries in a db table?
> > 
> 
> Autoincrements can work in a replicated enviroment, lookup 
> mysql settings auto_increment_increment & auto_increment_offset.
> 
> Each server gets its own unique auto_increment_offset, and 
> auto_increment_increment is set to the number of servers you have.
> 
> Jared
> 

Hmm, 

actually I'm using circular replication, so it's a bit different than
one way replication.

A replicates to B which replicates to A.

I've looked at the MySQL docs and can't find anything on how to make
Auto_Increment work in Circular Replication.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating a unique index ID

2006-03-13 Thread Jochem Maas

Jeff wrote:

-Original Message-
From: Jared Williams [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 13, 2006 10:16

To: 'Jeff'; php-general@lists.php.net
Subject: RE: [PHP] Creating a unique index ID






Hey all,

I've got a project where I'm taking form information from the
user and writing records to several tables in a MySQL database.

The problem I'm having is I need to write a unique number for
the ID column of the records.  Auto increment won't work 
because I could have conflicts due to replication of the 
database servers.  Anyone have any techique they use for 
creating unique ID field entries in a db table?




Autoincrements can work in a replicated enviroment, lookup 
mysql settings auto_increment_increment & auto_increment_offset.


Each server gets its own unique auto_increment_offset, and 
auto_increment_increment is set to the number of servers you have.


Jared




Hmm, 


actually I'm using circular replication, so it's a bit different than
one way replication.

A replicates to B which replicates to A.


isn't that called synchronization? not that it matters. :-)



I've looked at the MySQL docs and can't find anything on how to make
Auto_Increment work in Circular Replication.


just a thought(tm):

it's probably considered hackish (don't know why) but how about setting
up a seperate server/instance-of MySQL whose ONLY job it is to provide new ids,
and then configure each system to connect [remotely] to the aforementioned
db whenever a new id is required... which will probably require some
rewriting if you normally use mysql_insert_id() after a query to determine an
id (with my proposal you are forced to explicitly generate an id before hand)





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating a unique index ID

2006-03-13 Thread Jeff
> -Original Message-
> From: Jared Williams [mailto:[EMAIL PROTECTED] 
> Sent: Monday, March 13, 2006 10:16
> To: 'Jeff'; php-general@lists.php.net
> Subject: RE: [PHP] Creating a unique index ID
> 
> 
>  
> 
> > Hey all,
> > 
> > I've got a project where I'm taking form information from the
> > user and writing records to several tables in a MySQL database.
> > 
> > The problem I'm having is I need to write a unique number for
> > the ID column of the records.  Auto increment won't work 
> > because I could have conflicts due to replication of the 
> > database servers.  Anyone have any techique they use for 
> > creating unique ID field entries in a db table?
> > 
> 
> Autoincrements can work in a replicated enviroment, lookup 
> mysql settings auto_increment_increment & auto_increment_offset.
> 
> Each server gets its own unique auto_increment_offset, and 
> auto_increment_increment is set to the number of servers you have.
> 
> Jared
> 

Hmm, 

actually I'm using circular replication, so it's a bit different than
one way replication.

A replicates to B which replicates to A.

I've looked at the MySQL docs and can't find anything on how to make
Auto_Increment work in Circular Replication.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating a unique index ID

2006-03-13 Thread Jared Williams
 

> Hey all,
> 
> I've got a project where I'm taking form information from the 
> user and writing records to several tables in a MySQL database.
> 
> The problem I'm having is I need to write a unique number for 
> the ID column of the records.  Auto increment won't work 
> because I could have conflicts due to replication of the 
> database servers.  Anyone have any techique they use for 
> creating unique ID field entries in a db table?
> 

Autoincrements can work in a replicated enviroment, lookup mysql settings 
auto_increment_increment & auto_increment_offset.

Each server gets its own unique auto_increment_offset, and 
auto_increment_increment is set to the number of servers you have.

Jared

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Creating a unique index ID

2006-03-13 Thread Jim Moseby
> I've got a project where I'm taking form information from the user and
> writing records to several tables in a MySQL database.
> 
> The problem I'm having is I need to write a unique number for the ID
> column of the records.  Auto increment won't work because I could have
> conflicts due to replication of the database servers.  Anyone have any
> techique they use for creating unique ID field entries in a db table?
> 
> I was thinking maybe using a random 3 digit number and a unix 
> timestamp?
> 

Maybe this will work for you?

http://us2.php.net/manual/en/function.uniqid.php

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php