今天,我在$ wpdb中遇到了一个问题。
我用过
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d",
$report_id
)
);
由于mysql DATE_FORMAT
中的%d,上述代码无效。
我是如何在wordpress中解决这个问题的。
答案 0 :(得分:10)
试试这个:
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT DATE_FORMAT(report_date, '%%d-%%m-%%Y') FROM table WHERE report_id = %d",
$report_id
)
);
您需要使用%
%%