I have a SQL query string like this:
SELECT * FROM `oc_product` WHERE `manufacturer_id` = ? AND `date_added` < ? `product_id` IN (?) AND `price` > ? ORDER BY `product_id` ASC;
This is handed over to a Query class constructor like this:
$query = new Query("SELECT * FROM `oc_product` WHERE `manufacturer_id` = ? AND `date_added` < ? `product_id` IN (?) AND `price` > ? ORDER BY `product_id` ASC;", 27, date("Y-m-d H:i:s"), [17,18,29,30,46,47], 27.75);
I currently have a function which explodes the string with the question mark as the delimiter, count the number of marks and traverse the parameters, re-composing the query string so, for each parameter which is an array, I sustitute its question mark with as many question marks as parameters are in the array (so, instead of being IN (?) it gets corrected like IN (?,?,?,?,?,?)).
However, I don't like how my function looks like and would like to find a better equivalente or, if possible, a regex/function/SPL-driven procedure to make the substitution far easier than I have currently done.
Could you give me a hint?
sprintf()function, so I pass the query and then, all involved parameters, which are taken with thefunc_get_args()function. The idea is not to have any fixed/assumed condition, so I must process the query after it has been given, not before