Hi List,

Let's suppose I have these two tables:

CREATE TABLE `changes` (
  `ID` int(12) unsigned NOT NULL auto_increment,
  `Key` varchar(25) collate latin1_general_cs NOT NULL default '',
  `Table` varchar(25) collate latin1_general_cs NOT NULL default '',
  `Value` text collate latin1_general_cs NOT NULL default '',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
AUTO_INCREMENT=1;


CREATE TABLE `staff` (
  `ID` int(3) unsigned NOT NULL auto_increment,
  `Name` varchar(35) collate latin1_general_cs NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
AUTO_INCREMENT=1;

The idea is to have a audit trail to record the changes made. So, I want to
insert a new record in the "staff" table and right after this, insert a
record in the "changes" table.

SET AUTOCOMMIT=0;
START TRANSACTION;
INSERT INTO staff (`Name`) VALUES ('ABC');
INSERT INTO changes (`Key`, `Table`, `Value`) VALUES (LAST_INSERT_ID(),
'staff', 'ABC');
COMMIT;
SET AUTOCOMMIT=1;

This works fine in my test environment, however what about many users doing
at the same time. Does the LAST_INSERT_ID() get the correct ID for each
user?

Is there a better way to do this or this is fine? I will be using this with
PHP4.

Thanks for any help.

Andre




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to