note 97184 modified in function.mysql-insert-id by danbrown
| From: | danbrown@php.net | Date: | Wed, 07 Apr 2010 13:29:24 +0000 |
| Subject: | note 97184 modified in function.mysql-insert-id by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167749@lists.php.net to get a copy of this message | ||
if trying to insert a generated random id use mysql's UUID() to generate a unique key for you,
there should be a lot less problems with it.
<?php
$query = sprintf( "INSERT INTO
users"
."(id ,username)"
."VALUES"
."(UUID(),'%s' )",
mysql_real_escape_string($user)
);
if( !mysql_query($query) )
{/*insert failed*/}
$id = mysql_insert_id();
?>
--was--
if trying to insert a generated random id use mysql's UUID() to generate a unique key for you,
there should be a lot less problems with it.
$query = sprintf( "INSERT INTO users"
."(id ,username)"
."VALUES"
."(UUID(),'%s' )",
mysql_real_escape_string($user)
);
if( !mysql_query($query) )
{/*insert failed*/}
$id = mysql_insert_id();
http://php.net/manual/en/function.mysql-insert-id.php