I'm wondering if someone can explain to me why prepared statements like in the post above should not have semicolons to terminate them.
That would be hard, because actually what you state is just plain wrong. There is no problem with prepared statements that are terminated by a semicolon.
So while you wonder, don't wonder any longer. There is nothing to explain about the semicolon. It's just a delimiter character. For example I can run the following prepare just fine:
$stmt = $conn->prepare('
INSERT INTO config (`option`) VALUES (:option);;;;;
');
$result = $stmt->execute([':option' => "Insert Option " . uniqid() ]);
Make $result
being bool(true)
, the row is inserted. You haven't shared your code, so it's hard to tell what you do and what fails with you, but semicolons can be stacked even for fun as you can see.
I've used many PDO prepared statements with semicolons and never had problems until a few days ago.
That is a clear sign that the semicolon is not the problem actually. Otherwise all queries must have failed already from the very beginning.
I can't find anything in the PDO documentation about semicolon usage, so I'm confused about whether there's an underlying principle about whether or not to use them. Is it always a bad idea to use semicolons in prepared statements? If so, why?
Because it's part of the SQL. Consult the SQL documentation of the database server you're using. It does outline all the glory details of the use of the semicolon. It's just that this is not part of PDO itself, so it's not documented with PDO but with your database server.