brettz9's blog

Auto-escaping variables via EzSQL

Hi all,

In case it may be useful for someone, I made this ad-hoc solution to allow auto-escaping of variables. The advantage of this approach is that one can embed the variables directly within the query (not needing to pass the variables separately). The only thing you have to do is add a backslash before the variable. I've written it for MySQL, but I think you should be able to use the approach to add this for other databases that allow such escaping.

This is pretty much my first time doing anything with object oriented code, so my approach may be off base (let me know). But, it does seem to work. This approach has one disadvantage though; any variables to be escaped in this way have to be declared global if they are within a function, as must your object itself. This may limit its use for some people, but to get this ease of use, I really couldn't find any other way to implement it.

Syndicate content