public function getAutoIncrement($model)
{
if (class_exists($model)) {
$class = new $model;
$tableName = $class->tableName();
if (strpos($tableName, ".")) {
$table = ltrim(strrchr($tableName, "."), ".");
} else {
$table = $tableName;
}
$command = $class->getDbConnection()->createCommand("SHOW TABLE STATUS LIKE '$table'");
$res = $command->queryRow();
$nextId = $res['Auto_increment'];
return $nextId;
} else {
return 0;
}
}
ltrim(strrchr($tableName, "."), "."); //获取表名 e.g. tbcms.content -> content
SHOW TABLE STATUS LIKE '$table' //mysql语法 查看表的存储引擎结构