i am using safemysql class for parametrized queries https://github.com/colshrapnel/safemysql. Usualy, when preparing a query, it goes like this:
$entries = $db->getAll("SELECT * FROM table WHERE age = ?i AND name = ?s ",$age,$name);
This kind of queries where i know in advance the total number of parametres to be parsed are pretty straight fwd but it seems i am stacked at queries where I do not know how many parametres I will be using - eg. a search form:
What I would like to do, is parametrize the folowing query:
if($_POST['nameparts']){
$parts = explode(' ',$_POST['nameparts']);
foreach((array)$parts as $part){
$q .= " AND ( `name` LIKE '%".$part."%' OR `firstname` LIKE '%".$part."%' ) ";
}
if($_POST['age'])
$q .= " AND `age` = '".$_POST['age']."' ";
$entries = $dbs->getAll("SELECT * FROM table WHERE 1 = 1 ".$q." ");
Any suggestions?