标签归档:prepare

Missing argument 2 for wpdb::prepare()

wordpress升级到3.5突然出现这个问题 去footer.php查看
$post_datetimes = $wpdb->get_row($wpdb->prepare(“SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970″));
预处理丢失了一个参数
改为这样既可
$post_datetimes = $wpdb->get_row($wpdb->prepare(“SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > %d”,’1970′));
和C语言差不多 动态绑定参数

再给个普遍点的例子,这样写法是正确的:

$wpdb->prepare( “SELECT * FROM table WHERE id = %d”, $id );