Guest User

Untitled

a guest
Aug 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. Thread safe way to get auto incremented primary key inserted into another table (so they can be joined later)
  2. $result = mysql_query("SHOW TABLE STATUS LIKE 'table_name'");
  3. $row = mysql_fetch_array($result);
  4. $nextId = $row['Auto_increment'];
  5. mysql_free_result($result);
  6.  
  7. $sql = mysql_query("INSERT the information you want in the main table")
  8.  
  9. START TRANSACTION;
  10. INSERT INTO files (file_id, url) VALUES (NULL, 'text.doc');
  11. INSERT INTO grades (file_id, grade) VALUES (LAST_INSERT_ID(), 'some-grade');
  12. COMMIT;
Add Comment
Please, Sign In to add comment