php - How I get next auto-increment ID in mysql table? -


i need next auto-increment id mysql product table.

this how tried it:

select `auto_increment`  information_schema.tables table_name = 'products'; 

when query running, can output this.

+----------------+ | auto_increment | +----------------+ |             10 | |              1 | |             14 | +----------------+ 3 rows in set (0.02 sec) 

can tell me why shows 3 values. (3 rows)

note: product table still empty.

mysql> select * products; empty set (0.00 sec) 

run query

show table status 'products' 

using php

$result = mysql_query("     show table status 'products' "); $data = mysql_fetch_assoc($result); $next_increment = $data['auto_increment']; 

using mysqli

$db = new mysqli('your_host', 'db_username', 'db_password', 'database');  if($db->connect_errno > 0){     die('unable connect database [' . $db->connect_error . ']'); }  $sql = <<<sql show table status 'products' sql;  if(!$result = $db->query($sql)){     die('there error running query [' . $db->error . ']'); }  $row = $result->fetch_assoc();  echo $row['auto_increment']; 

details https://stackoverflow.com/a/1372115


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -