Problems with php: mysql_insert_id ()

Can php function mysql_insert_id () not return the result after processing the INSERT request in mysql db?

Just to clarify. A cron execution script was executed at the production site. It contains a cycle for creating invoices for users. Each iteration consists of a db INSERT request and the mysql_insert_id () operation immediately after the request - to retrieve the generated account number. A set of iterations was performed without retrieving the last inserted number.

Could this be caused by loading the server with high db or some other reasons that are not related to the problem on the php code site?

Any help would be appreciated!

+3
source share
2

, , MySQL :

  • , , AUTO_INCREMENT ed.
  • .
  • mysql_insert_id() , INSERT.
  • INSERT (, ). , mysql_query(), mysql_errno() mysql_error().

MySQL , .

, , MySQL , MySQL, .

+3

script , ;


mysql -e "insert into table ( field1 ) values ( 'val1' );" "database"

lastId=`mysql -e "select last_insert_id();" "database"`

, . - , / ;


lastId=`mysql -e "
                  insert into table ( field1 ) values ( 'val1' );
                  select last_insert_id();
                 " "database"`

, MySQL, - , !

0

Source: https://habr.com/ru/post/1763507/


All Articles