插入php后获取生成的uuid [英] Get the generated uuid after insert php
本文介绍了插入php后获取生成的uuid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表字段类型为varchar(36),我想由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);
在插入记录后如何立即检索生成的uuid?
how can i retrieve the generated uuid immediately after inserting the record ?
推荐答案
-
char(36)
更好 -
您不能.唯一的解决方案是执行2个单独的查询:
char(36)
is betteryou cannot. The only solution is to perform 2 separated queries:
-
SELECT UUID()
-
INSERT INTO table1 (id, text) VALUES ($uuid, 'text')
SELECT UUID()
INSERT INTO table1 (id, text) VALUES ($uuid, 'text')
其中$ uuid是第一步中获取的值.
where $uuid is the value retrieved on the 1st step.
这篇关于插入php后获取生成的uuid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文