Jump to content

Protecting against SQL injection


devWhiz

Recommended Posts

Would this be effective in protecting against SQL injection?

 

function runQuery($sqlQuery){
	$sqlQuery = str_replace(array('@@','))'),'\"',$sqlQuery);
	$sqlQuery = str_replace(array('++','--'),"\'",$sqlQuery);
	$sqlQuery = str_replace(array('**','&&'),' ',$sqlQuery);
	$runQuery = mysql_query($sqlQuery) or die(mysql_error());
	return $runQuery;
}

Link to comment
https://forums.phpfreaks.com/topic/253977-protecting-against-sql-injection/
Share on other sites

No, you would call it on all values that are of the string data type, that will be used in a DB query string.

 

// connect to database first
$string_value = mysql_real_escape_string($string_value);
$query = "SELECT field FROM table WHERE some_field = '$string_value'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.