0
hello everyone would like to know how to run two querys at the same time in php the situation and the following intend to do an Insert and return the auto_increment key I am doing the following
$query = "INSERT INTO usuario(cd_usuario,nome_usuario)VALUES ('0000','Fabricio')ON DUPLICATE KEY UPDATE nome_usuario = 'Fabricio Silva';SELECT LAST_INSERT_ID() AS ID";
$query = mysqli_multi_query($conexao,$query);//Ate aqui funciona
$query = mysqli_store_result($query);
$query = mysqli_fetch_array($query);
In this case you will not activate ON DUPLI.... because I am having new key generated, I need to recover the user id to assign an image to it
You need to call the
mysqli_next_result()
first.– Inkeliz
could exemplify and explain for what purpose ?
– Fabricio Silva
It’s no longer simple to use mysqli_insert_id to get the entered record id?
– rray
did not know the command vo a look
– Fabricio Silva
uaaau worked perfectly with the very simple code the last doubt and if you do not run the risk of it picking up an id from another section or at the time I pick up the id of the bank could be from another register
– Fabricio Silva
You don’t have that problem.
– rray
This is called "race condition", but Mysql will get the last id of the current connection and not the last one of the database when calling the function, so there is no problem. Well, actually there is a specific condition for this to occur, which is not your case. This occurs only if using replicates (Master - Master in "Active-Active Mode"), collision of
AUTO_INCREMENT
between banks, but this is a Mysql problem, which is "predictable" in this type of replica. In this case you will have to use theauto_increment_increment
and theauto_increment_offset
.– Inkeliz