复制代码 代码如下:
CREATE TABLE auto_id(
idname varchar(20) NOT NULL DEFAULT '',
id bigint(20) NOT NULL DEFAULT 0 COMMENT '',
primary key(idname)
)ENGINE=Innodb DEFAULT CHARSET=utf8;
复制代码 代码如下:
delimiter //
drop procedure if exists get_increment_id;
create procedure get_increment_id(in idname_in varchar(20), in small_in bigint, out id_out bigint)
begin
declare oldid bigint;
start transaction;
select id into oldid from maibo_auto_id where idname=idname_in for update;
if oldid is NULL then
insert into maibo_auto_id(idname,id) value(idname_in, small_in);
set id_out=small_in;
else
update maibo_auto_id set id=id+1 where idname=idname_in;
set id_out=oldid+1;
end if;
commit;
end;
//
复制代码 代码如下:
$sql = "call get_increment_id('{$key}', {$small}, @id)";
$ret = $db->getData("select @id");
复制代码 代码如下:
create table test(
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
primary key (id)
)ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
复制代码 代码如下:
UPDATE test SET id = LAST_INSERT_ID(id + 1);
SELECT LAST_INSERT_ID();
新闻热点
疑难解答