1
I have a table with some records, I want to change two rows of this table at the same time
I’m currently doing this:
include("conexao.php");
$tabela1 = "endereco";
$endereco_id= "75";
$antigo_endereco_id= "73";
$res = $pdo->prepare("UPDATE $tabela1 SET $tabela1.endereco_favorito = 0
WHERE $tabela1.endereco_id = :antigo_endereco_id");
$res->bindParam(':antigo_endereco_id',$antigo_endereco_id);
$res->execute();
$res = $pdo->prepare("UPDATE $tabela1 SET $tabela1.endereco_favorito = 1
WHERE $tabela1.endereco_id = :endereco_id");
$res->bindParam(':endereco_id',$endereco_id);
$res->execute();
But wanted some way to do both updates at the same time, do one after the other is causing problems that sometimes only one works and Leave the database
Have you ever thought of executing them within a transaction?
– anonimo
Could you give me more information about this ? I’m new in the database area :)
– Cicero Alysson
See: https://dev.mysql.com/doc/refman/8.0/en/mysql-acid.html
– anonimo