sprintf - how do i use an array as replacement values?
Posted: Tue Jan 26, 2010 1:03 am
I'm trying to build a really simple db class for this lame project I'm working on. I want to build an "buildQuery" method that basically just applies sprintf to a query. For instance:
The method would work something like this:
The problem is that this doesn't do what I intend it to do. sprintf expects a variable length list of arguments rather than an array. I need to use an array, so how do I go about this? Am I missing something obvious? 
Code: Select all
$db->buildQuery("UPDATE `users` SET `active` = %d WHERE `activation_code` = '%s'", array(1, 'a88jek3kl'));Code: Select all
// ..snip
public function buildQuery($query, $values) {
return sprintf($query, $values);
}
// ..snip