if you check on the FIRST insert (the primary table that holds "master"
usernames) to ensure the uname doesn't exist, THEN do the other queries,
there shouldn't be a problem.


I think the key here is that you're using the username as the unique key,
and putting that username in multiple tables... really, you should be taking
advantage of mysql's auto-increment on an ID field... therefor the username
"brad_is_the_best_2002" is an alias of userid "204"... all your other tables
(bb etc) should be using "204" as the id, not "brad_is_the_best_2002"...

1. gives people the chance to change usernames, because the ID is primary,
not the username

2. saves HEAPS of space:
Consider using 10 character unames everywhere:
1000 users x 10 char uname x 10 BB posts each = 100k of data -- not too bad
5000 users x 10 char uname x 50 BB posts each = 2.5meg of data -- an issue
5000 users x 15 char uname x 50 BB posts each = 3.75meg of data -- an issue

Then consider using 4 byte userIDs (like 1042) everywhere:
1000 users x 4 byte uid x 10 BB posts each = 40k of data -- better
5000 users x 4 byte uid x 50 BB posts each = 1 meg of data -- 60% space save
5000 users x 4 byte uid x 50 BB posts each = 1 meg of data -- 74% space save

... and in practice, the first 99 uid's will only be 2 bytes, the next 900
will only be 3 bytes, etc etc.


I'm no database expert, but I guess that's the point behind relational
databases... the same user can be related to many tables, using just a few
bytes of data, rather than a 6-20 character username.


So, after your first insert into the primary user table, you would find out
what ID you just inserted with mysql_insert_id(), and use THAT to insert
into the related tables...

Of course, your BB may require a full username, and lots of your other
architecture may have to be changed, but I'm just pointing out that it's
worth getting this stuff right, because one day you'll copy the same
code/structure to another site, and it may attract 100,000 users really
quick, and you might end up with a MASSIVE data problem REALLY quick -- it's
happened to me :)


Justin French

on 20/02/03 11:34 AM, Chris McCluskey ([EMAIL PROTECTED]) wrote:

> MySql should insert a value into that column when you update if you are using
> an auto_increment field.  this value will always be unique.  period.
> 
> -Chris
> 
> -----Original Message-----
> From: Chad Day [mailto:[EMAIL PROTECTED]]
> Sent: Wed 2/19/2003 1:16 PM
> To: php general 
> Cc: 
> Subject: [PHP] problem with mysql / auto increment fields.. ?
> 
> 
> 
> On my website there are a couple places where people can sign up ..
> 
> The querys after the sign up process look like
> 
> $blahblah = query(insert firstname lastname) values (blah blah blah)
> $userid = mysql_insert_id($blahblah);
> 
> $insertintoothertable = query(userid, blah blah blah) etc.
> 
> it then uses this userid var to insert them into a variety of other tables
> for other things on the site, such as a phpBB account, etc.
> 
> if multiple people are signing up for accounts at different places, is there
> the possibility that a duplicate userid could be assigned, or anything like
> that?
> 
> Thanks,
> Chad
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 8b°?¨¥S´?w??º?


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

Reply via email to