dpx49470 2013-07-19 00:50
浏览 100
已采纳

使用PHP获取MySQL插入的主键

I have looked through the documentation for this, but it is all about auto-increment.

I generate a key using a trigger and MySQL's UUID() function (I need these keys to be unique across databases that may or may not ever interact).

I use a trigger to generate the UUID()

How would I retrieve that key on an insert?

  • 写回答

3条回答 默认 最新

  • dongshou2017 2013-07-19 00:55
    关注

    Pass the UUID created by the trigger on a variable (@last_uuid)

    CREATE TRIGGER ai_uuidtable
    AFTER INSERT ON uuidtable
    FOR EACH ROW
    SET @last_uuid = NEW.uuid;
    

    Then you can retrieve the value using a query

    SELECT @last_uuid
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services