How can I avoid using Heredoc string delimiters for SQL statements? Or maybe a better question, what is the modern way to create and call SQL statements in PHP?
I am relatively new to php. I often saw something like this in the projects I was working on:
$sql = <<<SQL
SELECT
`data`.`key`,
FROM `tableName`
ORDER BY `data`.`key`
SQL;
When researching more about Heredoc (I had to use the SO symbol reference post to find what it was called) I got the feeling that there are better ways to make SQL statements. For exapmle SO users would say they used Heredoc for SQL "back in the day".
Using Heredoc seems to not be the best solution as little formatting changes can mess it up. Not being able to indent the closing tag makes the code harder to read and format. It also seems like just using Heredoc encourages littering the code with SQL statements and logic.
Is that just the 'way it's done' or is there a better way?
This question about managing your SQL queries is from 6 years ago. PDO or an ORM are mentioned in this answer from 5 years ago. Are these still the best way?