PHP mysql_insert_id()用于MySQL UUID()主键? [英] PHP mysql_insert_id() for MySQL UUID() primary keys?
问题描述
是否存在与PHP mysql_insert_id
等效的功能,以获取最后插入的UUID()主键? (我总是得到0.尽管它适用于auto_inc整数)
Is there some equivalent to PHP mysql_insert_id
to fetch the last inserted UUID() primary key? (I always get 0. It works for auto_inc integers though)
推荐答案
否,last_insert_id()仅检索最后生成的auto_increment字段.您必须先执行select uuid()
,然后使用该uuid进行插入.
No, last_insert_id() only retrieves that last generated auto_increment fields. You'll have to do a select uuid()
first, then do an insert using that uuid.
但是,请注意,不能保证uuid是唯一的-它们几乎不可能碰撞.如果您确实需要唯一性,则可以使用auto_increment-它们将永远不会在任何单个表中重复使用.
However, note that uuids can't be guaranteed to be unique - they're simply very unlikely to collide. If you do require uniqueness, then go with an auto_increment - they'll never be re-used within any single table.
这篇关于PHP mysql_insert_id()用于MySQL UUID()主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!