Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it OK to allow sometimes dynamic SQL without sanitization?
    primarykey
    data
    text
    <p>My partner on a PHP project objects my practice of always sanitizing integer values in dynamic SQL. We do use parameterized queries when possible. But for UPDATE and DELETE conditions <code>Zend_Db_Adapter</code> requires a non-parameterized SQL string. That's why I, even without thinking, always write something like:</p> <pre><code>$db-&gt;delete('table_foo', 'id = ' . intval($obj-&gt;get_id())); </code></pre> <p>Which is equivalent, but is a shorter version of (I've checked the ZF source code):</p> <pre><code>$db-&gt;delete('table_foo', $db-&gt;qouteInto('id = ?', $obj-&gt;get_id(), 'INTEGER')); </code></pre> <p>My partner strongly objects this <code>intval()</code>, saying that if <code>$obj</code> ID is null (the object is not yet saved to DB), I will not notice an error, and the DB operation will just silently execute. That's what has actually happened to him.</p> <p>He says that if we sanitize all the HTML forms input, there's no way an integer ID can possibly get into <code>'; DROP TABLE ...'</code>, or <code>' OR 1 = 1</code>', or another nasty value, and get inserted into our SQL queries. Thus, I'm just paranoid, and am making our lives unnecessarily more complicated. "Stop trusting the <code>$_SESSION</code> values then" he says.</p> <p>However, for string value conditions he does agree with:</p> <pre><code>$db-&gt;update-&gt;( 'table_foo', $columns, 'string_column_bar = ' . $db-&gt;qoute($string_value)) ); </code></pre> <p>I failed to prove him wrong, and he failed to prove me wrong. Can you do either?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload