This gets last X records ordered by ID descreasingly. If your ID is autoincremented, those will be the latest inserted values.
SELECT * FROM exp_channel_titles
ORDER BY id DESC
LIMIT X
Вопрос
One single Query to insert multiple rows :
$My query = "INSERT INTO exp_channel_titles(channel_id,author_id,ip_address) VALUES(11,1,'203.109.119.2'),(11,1,'203.109.119.2'),(11,1,'203.109.119.2')";
What I want :
array of auto incremented id.
what i am getting using SELECT LAST_INSERT_ID()
:
I get only one single id.What should I do so that I get array of all the auto incremented value of last inserted fields.
P.S : I cant fire multiple insert query.
Решение 2
This gets last X records ordered by ID descreasingly. If your ID is autoincremented, those will be the latest inserted values.
SELECT * FROM exp_channel_titles
ORDER BY id DESC
LIMIT X
Другие советы
if you are using InnoDB on a recent version of MySQL, you can get the list of IDs using LAST_INSERT_ID() and ROW_COUNT().
InnoDB guarantees sequential numbers for AUTO INCREMENT when doing bulk inserts, provided innodb_autoinc_lock_mode is set to 0 (traditional) or 1 (consecutive). Consequently you can get the first ID from LAST_INSERT_ID() and the last by adding ROW_COUNT()-1.