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

前端 未结 8 788
挽巷
挽巷 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 11:52

    well, try this:

    $query = "SHOW TABLE STATUS LIKE 'tablename'";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    var_dump($row);
    

    output:

    array(18) {
    [...]
    ["Auto_increment"]=> string(4) "3847"
    [...]
    }
    

    This will be your next auto_increment ID.

提交回复
热议问题