List:MySQL on Win32« Previous MessageNext Message »
From:Michael Widenius Date:August 1 1999 8:59pm
Subject:last_insert_id() - strong behavior
View as plain text  
Hi!

>>>>> "Ives" == Ives Steglich <Ives> writes:

Ives> hi there i got a little problem with
Ives> this funny last_insert_id() function

Ives> i use mysqld-opt for windows Ver 3.21.29a-gamma
Ives> for development at the moment
Ives> the system have than to move to a sgi chellange
Ives> but there the mysql db isn't setuped till know
Ives> so i hope at the unix system with a newer version
Ives> this problem doesn't occour anymore

Ives> and i don't know what the heck goes wrong there

Ives> ok i've some tables that matter to this problem:

Ives> CREATE TABLE Person(
Ives> PersID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Ives> Anrede ENUM("Herr", "Frau") DEFAULT "Herr",
Ives> Titel CHAR(50),
Ives> Vorname CHAR(20) NOT NULL,
Ives> Name CHAR(30) NOT NULL,
Ives> AdrID INT UNSIGNED REFERENCES Adresse,
Ives> Bemerkung CHAR(200),
Ives> PRIMARY KEY (PersID));

Ives> CREATE TABLE Mitarbeiter(
Ives> MitID	INT UNSIGNED NOT NULL AUTO_INCREMENT,
Ives> PersID INT UNSIGNED NOT NULL REFERENCES Person,
Ives> AdrID	INT UNSIGNED REFERENCES Adresse,
Ives> InstID INT UNSIGNED REFERENCES Institut,
Ives> Zimmer CHAR(20),
Ives> Organisation CHAR(100)	DEFAULT "Technische Universität Ilmenau",
Ives> Bemerkung CHAR(100),
Ives> PRIMARY KEY (MitID));

Ives> CREATE TABLE Kontakt(
Ives> KonID	INT UNSIGNED NOT NULL AUTO_INCREMENT,
Ives> PersID INT UNSIGNED NOT NULL REFERENCES Person,
Ives> Typ ENUM("Tel", "Fax", "Mobil", "eMail", "Web", "Pager"),
Ives> Inhalt CHAR(100) NOT NULL,
Ives> PRIMARY KEY (KonID));

Ives> and of course a set of action's in which the problem will occour:
Ives> (extracted out of a php3 script)

Ives> insert into Person (Anrede,Titel,Vorname,Name)
Ives>   values ('$anrede', '$titel', '$vorname', '$name')

Ives> insert into Mitarbeiter
Ives>   values (NULL, last_insert_id(), '$adresse', '$institut',
Ives>           '$zimmer', '$organisation', '$bemerkung')

Here you insert the auto_increment value from Person

Ives> insert into Kontakt
Ives>   values (NULL, last_insert_id(), 'eMail', '$email')

Here you insert the auto_increment value from Mitarbeiter (because you 
didn't specify a value for the auto_increment column)

Ives> insert into Kontakt
Ives>   values (NULL, last_insert_id(), 'Tel', '$tel')

Here you insert the auto_increment value from Kontakt !

Ives> ok looks good but doesn't work right - the problem occours
Ives> at the last query - the last_insert_id() gives me values
Ives> which doesnt exists in the person-table

Regards,
Monty
Thread
last_insert_id() - strong behaviorIves Steglich [Dalini]21 Jul
  • last_insert_id() - strong behaviorMichael Widenius2 Aug