Most of the time it does not make sense to have more than one auto increment field in a single table in a database. If you want to achieve this you will have to do this manually like mentioned above.
If you search Google from something like "multiple auto increment column in same table mysql" then you will find that there are limitations to what MySql can handle in the different storage engines. InnoDB has reservations about more than one autoinc field.
so to simulate this you can use the following code
Code:
CREATE TABLE `sequences` (
`id` double default NULL,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
PHP Code:
$sql = "SELECT count(*) as cnt
FROM sequences
WHERE name='{$sequence_name}'";
$res = $GLOBALS['db']->query($sql);
$row = $GLOBALS['db']->fetchByAssoc($res);
if($row['cnt'] != 1){
$sql = "INSERT INTO sequences (id, name)
VALUES (0, '{$sequence_name}')";
$res = $GLOBALS['db']->query($sql);
}
$sql = "UPDATE sequences SET id=LAST_INSERT_ID(id+1) WHERE name = '{$sequence_name}'";
$res = $GLOBALS['db']->query($sql);
$sql = "SELECT LAST_INSERT_ID() as LAST_INSERT_ID";
$res = $GLOBALS['db']->query($sql);
$row = $GLOBALS['db']->fetchByAssoc($res);
Regards
Kenneth Thorman
Bookmarks