Prepared statements tend to be the best answer for most cases which is similar to the approach you describe but is natively supported by most SQL dialects and also improves performance.
In my experience, many developers and even experienced security engineers can fail to give this answer though.