Hello.

Tell me, is it possible to get the identifiers of the inserted rows (preferably using PHP) if they are inserted without locking the table (myisam)?

INSERT INTO table (row1, row1) VALUES(2, 3), (5, 2), (7, 9); 

    2 answers 2

    If I understood correctly, you need mysql_insert_id , for PDO lastInsertId();

    If it is necessary for multiple insertion, then there are no embedded solutions (at least I don’t know), but try this

    mysql_insert_id() will issue the first id

    mysql_insert_id() + 2 - will give the last identifier - this is exactly in your case. - that is, we add (N-1), where N is the number of inserted data.

    A little googling that's what I found

     /** * Возвращает список всех вставленных ID с помощью multiInsert() **/ function get_all_insert_id($countLines) { $arID = array(); for ($i = mysql_insert_id(); $i <= (mysql_insert_id() + $countLines); $i++) { $arID[] = $i; } return $arID; } 
    • That's right, but not quite. This method will return the identifier of only one line of the 3 inserted, but I need all 3. - DemoS
    • This method is obvious in principle, but it seems to me that it is the place to be just with table locking. Because it is possible to insert in parallel with several such queries, and identifiers may overlap. In any case, thank you for your help, I will try! - DemoS
    • one
      about the intersections of the insert - as they say they can not be on myisam, right here take a look forum.searchengines.ru/archive/index.php/t-596333.html - Ale_x

    Probably pure PHP means impossible. Send a query of the type: SELECT id FROM table ORDER BY id DESC LIMIT 3

    • No, not at all. The problem does not solve the problem - DemoS