(mysql, php) How to get auto_increment field value before inserting data?

前端 未结 8 762
挽巷
挽巷 2020-11-29 11:10

I\'m uploading image file to storage server. Before uploading I should compose filename, which contains AUTOINCREMENT VALUE in it (for example, 12345_filename.jpg).

8条回答
  •  一生所求
    2020-11-29 12:00

    If you are using PDO, here is a "single line" solution :

    $nextId = $db->query("SHOW TABLE STATUS LIKE 'tablename'")->fetch(PDO::FETCH_ASSOC)['Auto_increment'];
    

    where tablename is replaced by your table.

提交回复
热议问题