My PHP project partner aims to always sanitize integer values in dynamic SQL. If possible, we use parameterized queries. But the UPDATE and DELETE conditions Zend_Db_Adapterrequire an unparameterized SQL string. That's why I, without even thinking, always write something like:
$db->delete('table_foo', 'id = ' . intval($obj->get_id()));
This is equivalent, but this is a shorter version (I checked the ZF source code):
$db->delete('table_foo', $db->qouteInto('id = ?', $obj->get_id(), 'INTEGER'));
My partner strongly objects to this intval(), saying that if the $objID is zero (the object has not yet been saved to the database), I will not notice an error, and the database operation will simply be performed silently. What really happened to him.
He says that if we sanitize all the entered HTML forms, there is no way for the integer ID to fall into '; DROP TABLE ...'either ' OR 1 = 1'or another unpleasant value and be inserted into our SQL queries. So I'm just paranoid and I make our lives unnecessarily complicated. "Stop trusting meanings $_SESSION, then," he says.
However, for string value conditions, he agrees with:
$db->update->(
'table_foo',
$columns,
'string_column_bar = ' . $db->qoute($string_value))
);
I could not prove that he was wrong, and he could not prove that I was wrong. Can you do it?