使用%s和%d的PHP MySQL查询

时间:2009-06-07 16:46:53

标签: php mysql

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

%s%d是什么?

2 个答案:

答案 0 :(得分:21)

这些是使用的格式符号,例如按sprintf()。例如:

<?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;
?>

输出:

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

答案 1 :(得分:7)

string 十进制整数可能是format symbols