admin管理员组文章数量:1323225
Today, I have a issue in $wpdb.
I used
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d",
$report_id
)
);
The above code not works because of %d in DATE_FORMAT. How i solved this issue in wordpress
Today, I have a issue in $wpdb.
I used
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d",
$report_id
)
);
The above code not works because of %d in DATE_FORMAT. How i solved this issue in wordpress
Share Improve this question asked Apr 8, 2014 at 18:07 Tamil Selvan CTamil Selvan C 3977 silver badges22 bronze badges1 Answer
Reset to default 5From the Codex page for the WPDB class:
[...] the
prepare
method [...] supports both asprintf()
-like andvsprintf()
-like syntax.
Having a look at PHP's documentation for sprintf()
:
##Example 6 ...
// notice the double %%, this prints a literal '%' character
So you can use
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT DATE_FORMAT(report_date, '%%d-%%m-%%Y') FROM table WHERE report_id = %d",
$report_id
)
);
for your purposes.
本文标签: wpdb prepare issue with mysql DATEFORMAT
版权声明:本文标题:$wpdb prepare issue with mysql DATE_FORMAT 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742072209a2419194.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论