This question already has an answer here:
I'd like to perform the following query:
SELECT *, (SELECT COUNT(*) FROM `tab2` WHERE `parent` = :id) AS `sum` FROM `tab1` WHERE `id` = :id
As you can see :id
placeholder appeared twice in the query. So if I'd try to execute this statement with:
$q->execute(['id'=>$row_id]);
I'm receiving the error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number
So I have to rewrite the prepared query and execute array with :id1 and :id2 placeholders which looks a bit stupid for me.
Is it the only way to use one placeholder in several places of the prepared statement?
</div>