Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DickJ41R's avatar

Practical PHP

In the Practical PHP section regarding the dynamic creation of query strings. I tried to extend the code by adding another field. With this change, sprintf threw an error which was related to the number of arguments. I was able to bypass issue by using ...explode to form the field and value arguments.

0 likes
2 replies
ejdelmonico's avatar

@DickJ41R You really need to post the code if you expect any replies. And sprintf() can only take the number of parameters as you have placeholders in the string. Also, the order in which you list the params must match the placeholder directives type.

DickJ41R's avatar

I did not expect any replies. I am fairly sure sprintf set up was correct. However, when adding the second field, e.g. email, at least my version of sprintf which with the exception of 2 addition %s to accommodate the field and associated value, kept return invalid number of arguments. it seems to be treating the results of the implode function as a single argument. The course only used a single value for the example. I felt that the dynamic creation of the sql string was important enough to see if it generalized.

Please or to participate in this conversation.