rondog Posted November 24, 2010 Share Posted November 24, 2010 If I am running a query like this: INSERT INTO `cam_locations` (`id`, `datacenter`, `address1`, `address2`, `city`, `state`, `zip`, `country`, `phone`) VALUES (1, 'Austin Data Center', '', '', 'Austin', 'Texas', '', 'United States', ''), (2, 'Sunnyvale Date Center', '', '', 'Sunnvale', 'California', '', 'United States', ''), (4, 'BoxBorough Data Center', '', '', 'Boston', 'Massachusetts', '', 'United States', '') It it possible to use mysql_insert_id() and get all the id's inserted? Maybe like an array of them or something? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219743-getting-mysql_insert_id-from-multiple-inserts/ Share on other sites More sharing options...
jim_keller Posted November 24, 2010 Share Posted November 24, 2010 Off the top of my head, I actually don't think this is possible; I believe it will always return the very last row inserted. You may just have to do your insert queries individually. Quote Link to comment https://forums.phpfreaks.com/topic/219743-getting-mysql_insert_id-from-multiple-inserts/#findComment-1139186 Share on other sites More sharing options...
rondog Posted November 24, 2010 Author Share Posted November 24, 2010 Ok that is what I was going to do if this wasn't possible. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219743-getting-mysql_insert_id-from-multiple-inserts/#findComment-1139190 Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 According to your query, aren't you inserting the ids explicitly? mysql_insert_id() only works when the table has an autoincrement field . . . Quote Link to comment https://forums.phpfreaks.com/topic/219743-getting-mysql_insert_id-from-multiple-inserts/#findComment-1139197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.