ebolt007 Posted January 23, 2012 Share Posted January 23, 2012 Since Mssql doesn't have an escape string for input information, is there anything that anyone has to protect inputs against sql injections? Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/ Share on other sites More sharing options...
premiso Posted January 23, 2012 Share Posted January 23, 2012 function mssql_escape($data) { if(is_numeric($data)) return $data; $unpacked = unpack('H*hex', $data); return '0x' . $unpacked['hex']; } Taken from: http://stackoverflow.com/a/574821/398519 Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/#findComment-1310448 Share on other sites More sharing options...
dzelenika Posted January 23, 2012 Share Posted January 23, 2012 Use prepared statements, so you don't need to worry about SQL injection. Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/#findComment-1310457 Share on other sites More sharing options...
ebolt007 Posted January 23, 2012 Author Share Posted January 23, 2012 This may be a retarded question, but I never really got the grasp of functions. How would I implement a function like this on a post of a variable like the following? Say I have a headline input field called: <input class="sign_up_input_area_main" type="text" name="Headline" value="<?echo $headline_2?>" size="98" /> and my post action is $headline_1 = trim($_POST['Headline']); $headline_2 = strip_tags($headline_1); $headline_3 = stripslashes(str_replace("'", "''", ($headline_2))); And what do you mean "prepared statements? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/#findComment-1310459 Share on other sites More sharing options...
dzelenika Posted January 23, 2012 Share Posted January 23, 2012 http://www.php.net/manual/en/pdo.prepare.php If you don't want to use PDO and you're on windows there's also excellent Microsoft's SQL Server Driver for PHP here available: http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/#findComment-1310461 Share on other sites More sharing options...
cpd Posted March 8, 2012 Share Posted March 8, 2012 MSSQL is discontinued as of PHP 5.2.x or something like that. The new more efficient method of connecting PHP with SQL Server is with the drivers specified above (SQLSRV). In answer to your question, you could use the function detailed by premiso - how secure that is I don't know. This would be implemented during the execution script where you process your form data. I personally feel a better method is to use stored procedures which (as far as I know) are near on impossible to break through as the syntax would just cripple the SQL Server if it were to be manipulated. Quote Link to comment https://forums.phpfreaks.com/topic/255627-no-mssql_real_escape_string/#findComment-1325204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.