sql - PHP security concerns around in clause that is a concatenated string -
given following code
<?php $values = array('foo' =>'foo' ,'bar' =>'bar' ); $separated = "'" . implode("','", $values)."'"; $sql = 'select name,age cats title in(' .$separated.')' ; print_r($sql); produces:
select name,age cats title in('foo','bar') is there need aware of sql injection using type of query builder? if so, attack can occur?
the rule of sql security:
no value should added query directly, via placeholder only
so, have use library supports placeholders.
assuming database mysql, best choice safemysql, let have simple code this:
$sql = 'select name,age cats title in(?a)'; $data = $db->getarr($sql, $values); print_r($data); or can use pdo, take a lot more trouble
Comments
Post a Comment