3 ms·
Exactly. You make a very good point. Passing PARAMETERS to a string based query or command should be done by reference whenever possible. The CALLER shouldn't b
by EGreg 9y ago
Exactly. You make a very good point. Passing PARAMETERS to a string based query or command should be done by reference whenever possible. The CALLER shouldn't be responsible for the escaping and interpolation. That is for the DRIVER or API or whatever.
That just further proves my point. When you call SQL commands from PHP you should use PDO and parametrized queries always. Values should always be passed by reference.
Same goes when you are outputting some HTML. You should have a hash of
{
attributeName: value
}
and it should be up to the HTML RENDERER - and not you - to escape the values every time.
You've made another great point, which layers on top of my point, which is:
1) Use each language Y as it was intended
2) Escape everything automatically by passing values by reference to an API layer in language X
So to sum up:
Use HTML for structure, CSS for appearance, and JS for all dynamic behaviors. Keep your files separate! Do not allow embedding arbitrary CSS and JS in your HTML and so on.
For MySQL use a MySQL driver API and pass values to it
For HTML use an HTML renderer API and pass values to it
For Javascript-accessible data embedded in HTML use a JSON function (easy) and pass values to it.
For JSONP (old school) use JSON wrapped with some callback. Better: load actual JSON using XHR and CORS. Best: use iframes and postMessage to execute arbitrary methods in the other domain via an authorized session.
And so on.