Search code examples
phpmysqlauto-increment

Get next auto increment


I know this isn't so complicated but I can't remember how to do.

I just need to know the next auto increment.

$result = mysql_query("
    SHOW TABLE STATUS LIKE Media
");
$data = mysql_fetch_assoc($result);
$next_increment = $data['Auto_increment'];

...but i won't work for me, what am I doing wrong?


Solution

  • $result = mysql_query("
        SHOW TABLE STATUS LIKE 'Media'
    ");
    $data = mysql_fetch_assoc($result);
    $next_increment = $data['Auto_increment'];
    

    The name of the table needed to be wrapped with single quotes like this: 'table_name'

    So it works just fine now.

    :)