As I have seen in many posts, dynamic SQL in stored procedure is vulnerable to SQL injection. But if we use previously PDO with prepared statement this still be unsafe?
Yes, of course.
What if in_var
is equal to ' UNION SELECT password from admins --
?
To avoid that, you should use not a cargo cult prepared statement but a real one, substituting your variable with a placeholder.
SET @query = CONCAT("SELECT * FROM my_table WHERE my_column = ? LIMIT 1;");
PREPARE stmt FROM @query;
EXECUTE stmt USING @in_var;