I can sanitize and validate my input as much as possible but that definitely doesn't cover everything and if I scrub hard enough, thoroughly enough, I will completely wipe away my input.
I realize there are a lot of posts out there about this topic but it seems like they always go back to PDO or Mysql (yes - even if someone posts about SQL Server, half the answers they receive suggest mysql_real_escape_string - crazy world). I cannot use either. Even as I type and the little "similar questions" appear on the right of my screen, I keep clicking on various links and nothing fully answers my question.
I am using SQL Server. I am using PHP 5.2.4. I cannot use PDO (because...? my boss said 'no' and that's enough reason).
Is there a way I could write a safe way to prepare my own query statements?
In the past, I have tried to build a statement like this in the PHP. (where $input_* variables are some form of user input or I pulled them out of something)
$query = "
declare @varID int
declare @var1 int
declare @var2 varchar(100)
set @varID = cast('$input_ID' as int)
set @var1 = cast('$input_var1' as int)
set @var2 = cast('$input_var2' as varchar(100))
update table_name_goes_here
set var1 = @var1,
var2 = @var2
where ID = @varID;
";
# $query is then executed
but that can be vulnerable, too... obviously.... And the last thing I do is remove all necessary punctuation (sometimes I know they will have no reason to use certain characters)
But there has to be some other option... right? And mssql_bind
only works for stored procedures, which is a definite option but I'm not sure if I want to volunteer to expand my responsibilities to include maintenance in the actual database by making insert/update procedures.