MySQL/PHP - auto increment and multipile records insertion

Problem 1:
Suppose we have a table with an auto-increment field. That is the id is set by the db and is incremented following each insertion. Now for the record of that id we link several resources or records of other tables. All of these records include a field that points to the auto-incremented id, but we don't know what it is!
MySQL saves the information of the last updated id per session. To access this information through php, use mysql_insertion_id();

Problem 2:
To insert several records at once to a table in MySQL we should use the syntax below:
INSERT INTO tablename(clm1, clm2, clm3, ... ) VALUES (first, second, third, ...), (first, second, third, ...), (first, second, third, ...), ...

Post a Comment

Previous Post Next Post