Mysql 查询:date_format 和 sprintf()
我想在 MySQL 查询中使用 sprintf() 和 date_format 。
这是查询:
mysql_select_db($database_exdb, $expdb);
$query_eventeditrs = sprintf("SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), timeofevent, location, details, presenter, bio FROM events WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
我收到错误:
“Warning: sprintf() [fun
ction.sprintf]: Too few arguments. Query was Empty”
请帮助
I want to use sprintf() along with date_format in a MySQL query.
Here is query:
mysql_select_db($database_exdb, $expdb);
$query_eventeditrs = sprintf("SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), timeofevent, location, details, presenter, bio FROM events WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
I am getting error that :
“Warning: sprintf() [fun
ction.sprintf]: Too few arguments. Query was Empty”
Plz help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须使用额外的 % 对日期格式字符串进行转义,请尝试以下操作:
You have to escape the date format string with extra %'s, try this:
您需要使用 mysql_query() 实际运行查询,请参阅 http://php.net /manual/en/function.mysql-query.php
You need to actually run the query using mysql_query() see http://php.net/manual/en/function.mysql-query.php
在 sprintf 字符串中,您有:
有
5
个输入,但您只输入 一个 (GetSQLValueString($colname_eventeditrs, "int")
) ,再输入 4 个,你应该是金色的(或者如下面评论中所述,转义 4 个输入,这也应该有效)In the sprintf string you have:
Which has
5
inputs, but you only put in one (GetSQLValueString($colname_eventeditrs, "int")
), put in 4 more and you should be golden (or as said below in the comments, escape 4 of the inputs and that should also work)