Why doesn't PDO allow multiple placeholders with the same name?

I use PHP and MySQL with PDO. Sometimes I need to prepare a statement with one variable (placeholder) used more than once in this query.

Example:

SELECT * FROM messages WHERE from_id = :user OR to_id = :user

However, if I try to prepare this statement, I will have an error, so I need to do this as follows:

SELECT * FROM messages WHERE from_id = :user1 OR to_id = :user2

To call this statement, I will need to have an array like this:

array('user1'=>$user_id, 'user2'=>$user_id);

It looks so stupid for me! Why does MySQL (PDO?) Prevent me from using one place holder more than once and forcing me to use additional variables that require more control ?!

, (, ), 5 (!!!) . , , , .

- ?

+4
1

- ?

, . . .

, , . , , Wez Furlong ( PDO):

; , , . , .

- . . , , , .

http://paul-m-jones.com/archives/243#comment-740

+9

Source: https://habr.com/ru/post/1669793/


All Articles