The one big problem with SQL is intermixing query language and query parameters. This requires escaping and is the source of many PHP vulnerabilities. Instead of
do_sql('SELECT * FROM tab WHERE name = "abc"')
there should have been a standard where you wrote do_sql('SELECT * FROM tab where name = V1", "abc")
or something like that. So you don't do string operations on the query parameters.