Wednesday, July 19, 2006

sql injection attacks increasing

PHP doesn't force you to do that by hand, you can make use of the numerous database abstraction layers for PHP, like PDO [php.net] or PEAR::DB [php.net].

Here is an example, taken straight from PDO's page:
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

$name = 'one';
$value = 1;
$stmt->execute();
The framework is there, PHP developers need to make use of it, but sadly things like the following are still common:
mysql_query('SELECT value FROM REGISTRY WHERE name = "' . $name . '"');

No comments: