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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -