R
R
ruslannasrutdinov2015-01-15 15:45:55
PHP
ruslannasrutdinov, 2015-01-15 15:45:55

How to select the value of the current auto_increment of a table?

Hello. Tell me please. Here is a table. The current value of Auto_increment = 30. This is the value I need to get. How can this be done using sql query or yii framework?e545772fe498489e98dd11f6b6842e17.PNG

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Nalomenko, 2015-01-15
@nalomenko

SELECT `AUTO_INCREMENT`
FROM  INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DatabaseName'
AND   TABLE_NAME   = 'TableName';

A
Anton, 2015-01-15
@Yadalay

$auto = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE 'table'"));
echo $auto['auto_increment'];
Where 'table' is the name of the table.

A
algebris, 2015-01-15
@algebris

if in YII, then Yii::app()->db->lastInsertID is possible;
if in MySQL, then you can use the SELECT LAST_INSERT_ID() function;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question