First - I know prepared statements are the "silver bullet" and I "should be using them" - however for this project, it's not feasable. Trust me when I say it cant happen. So, before the preaching starts... ;)
So, I've been reading for 4 hours tonight on SQL injection.
And EVERY rebuttal to using real_escape_string (I'm working with PHP and MySQL) says, basically, that real_escape_string wont stop this:
SELECT * FROM something WHERE id=1 or 1=1;
Right. Got it.
But since I first touched mysql about 15 years ago, every query I have EVER written has ALWAYS single quoted all parameters I send in a query. Like, if I don't single quote parameters, I have this ikky feeling the query will fail. So I ALWAYS single quote everything. All. The. Time.
And:
$_POST['userinput'] is submitted as "1 or 1=1";
$clean = $db->real_escape_string($_POST['userinput']);
$db->query("SELECT * FROM something WHERE id='$clean'");
How can that EVER be broken? Can it? I've never seen an example that shoots down real_escape_string that does NOT use the unquoted version.
It's in quotes. All inner quotes that could break out of the quoting are escaped.
Again: I know prepared statements are the best. Thats not what I'm asking. I'm asking if what I wrote above can be broken?
I dont see a way.