The PDO transaction examples at PHP.net show that PDO::exec() is transactioned, but there are no such examples using PDO::query().
Do transactions cover PDO::query()?
Also, as I understand, PDO::query() returns a result set. If transactioned, how can there be a result set, since the statement shouldn’t execute until committed? (Does this imply that PDO::query() is indeed not transactioned?) I can’t seem to find an official reference saying whether it is or it isn’t.
You missunderstand transactions. Transactions simply guarantee that the operations are atomic: either all operations succeed or none of them succeeds. Once you start a transaction every query will be executed and it will be logged in the transaction log. If an operation fails and you roll back, every operation will be reverted.
That said: if a query is transactionable does not depend on if you are using
execorquerybut it depends on the query type.INSERT,UPDATEandDELETEare transactionable, other operations (such asALTER TABLE) may or may not be transactionable, depending on your DBMS.