Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EbrahemSamer's avatar

Why PDO insert Query executed two times ?

I am inserting using this code

////////////////

$action_name = "بحث"; $action_doer_id = $_SESSION['user_id'];

$query = "INSERT INTO transactions (transaction_name, transaction_user_id, transaction_notes) VALUES ('$action_name', $action_doer_id, '$notes')";
$stmt = $pdo->query($query);
$stmt->execute();

//////////////

the result is two records added in database why ? ( note ) but there is a query before it should i call it query2 instead of query and stmt2 instead of stmt

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

Do you maybe make the request twice? add a dump() above these lines and check if your request is being repeated.

And which PDO class are you using? I tried with PDOConnection and there is no execute() method in it. Wanted to check if the query() method also executes the query.

Please or to participate in this conversation.