search

Home  >  Q&A  >  body text

mysql - Record the last newly added ID in PHP

I want to save and download the record ID last inserted into the database, and read it again when the download method is called. After inserting, the original record ID is overwritten. How to achieve better performance? Save to database? Save to file? Will the cache be flushed?

習慣沉默習慣沉默2752 days ago525

reply all(2)I'll reply

  • 某草草

    某草草2017-05-16 13:14:21

    Recursive algorithm fits this business

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:14:21

    If there is redis或者memcache作为缓存的话设置key永不过期可以解决(redis可持久化数据,但不排除宕机后丢失),每次插入后更新值,相对性能较好,保存数据库和文件也可以解决问题,也可以两者同时使用,既保存到数据库又放入缓存,更新时增加成本但可靠性更好,也可以换种思路,每次去数据库查询,对于innodb引擎的mysql数据表,主键查询效率较高,idIt is also a good solution to take the first one in reverse order. If a connection pool is used, the performance will be better.

    reply
    0
  • Cancelreply