7
I mostly agree with Brad. Maintainability is very important.
But a second can be a significant delay for a web page, especially in combination with delays caused by other factors. Howver, I'm sure that a single sprintf takes much less than a second.
Personally, I try to avoid using sprintf simply to achieve string concatenation.
Here's my preferred way of doing queries:
Example 1:
$challenges_table = $xoopsDB->prefix('chess_challenges');
$result = $xoopsDB->query("SELECT player1_uid FROM $challenges_table WHERE challenge_id = '$challenge_id'");
If the query is long, I break it up into separate lines to make it more readable.
Example 2:
$challenges_table = $xoopsDB->prefix('chess_challenges');
$result = $xoopsDB->query(trim("
SELECT game_type, fen, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) as create_date
FROM $challenges_table
WHERE challenge_id = '$challenge_id'
"));
(In XOOPS 2.0.7, the trim() isn't needed, since XoopsMySQLDatabaseProxy::query was modified to strip leading whitespace.)