The deep question here is to know when PDO returns true and when false.
Documentation says true if succeed false on fail. So what is succeed and fail in MySQL?
Here is my current question: I'm sending this query all together in one PDO execute and it returns true even foreign_id should not be NULL:
SET @id := NULL; SELECT id INTO @id FROM ? WHERE id = ? AND to_user = ?;
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
but if I send only
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
false is correctly returned.
N.B. NULL is only for testing purpose normally it's replaced by @id.
I tried further to see the behaviour of PDO:
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, ?);
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
Here the first insert is correct the second not and PDO returns true.. I'm getting to think that PDO returns true when only one query succeeds.
Can you please explain that to me so I know once for all how to deal with my database. because I based all my program on this principle:
execute('BEGIN')
execute(myquery) // which can be many selections, insertions updates together in one string
if succed execute('COMMIT')
else execute('ROLLBACK')