Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the generated uuid after insert php

Tags:

php

uuid

mysql

i have a table field type varchar(36) and i want to generate it dynamically by mysql so i used this code:

$sql_code = 'insert into table1 (id, text) values (uuid(),'some text');';
mysql_query($sql_code);

how can i retrieve the generated uuid immediately after inserting the record ?

like image 640
Alaa Jabre Avatar asked Feb 08 '11 12:02

Alaa Jabre


1 Answers

Its pretty easy actually you can pass this to mysql and it will return the inserted id.

set @id=UUID();
insert into <table>(<col1>,<col2>) values (@id,'another value');
select @id;
like image 176
roneo Avatar answered Oct 20 '22 23:10

roneo