12
SELECT COUNT(*) AS test FROM %s WHERE id = %d AND tmp_mail <> ''

What are %s and %d for?

1
  • 2
    Using sprintf() is marginally better than string concatenation. For a more robust approach though, you should look at Prepared Statements
    – kizzx2
    Commented Jun 7, 2009 at 17:06

2 Answers 2

22

Those are format symbols used e.g. by sprintf(). Example:

<?php
 $sql_template = "SELECT COUNT(*) AS test FROM %s WHERE id = %d AND tmp_mail <> ''";
 $sql_real = sprintf($sql_template, 'sometable', 12345);
 echo $sql_real;
?>

Output:

SELECT COUNT(*) AS test FROM sometable WHERE id = 12345 AND tmp_mail <> ''
7

That are probably format symbols for string and decimal integer.

Not the answer you're looking for? Browse other questions tagged or ask your own question.