[英]Mysql query : date_format and sprintf()
I want to use sprintf() along with date_format in a MySQL query.我想在 MySQL 查询中使用 sprintf() 和 date_format。
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请帮忙
You have to escape the date format string with extra %'s, try this:您必须使用额外的 % 来转义日期格式字符串,试试这个:
sprintf("SELECT eventid, groupid, title,
DATE_FORMAT(dateofevent, '%%W, %%M %%d, %%Y'),
ti meofevent, location, details, presenter, bio
FROM events
WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
In the sprintf string you have:在 sprintf 字符串中,您有:
"SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'),
timeofevent, location, details, presenter,
bio FROM events WHERE eventid = %s"
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)其中有
5
输入,但您只输入一个( GetSQLValueString($colname_eventeditrs, "int")
),再输入 4 个,您应该是金色的(或者如下评论中所述,转义 4 个输入,这也应该工作)
You need to actually run the query using mysql_query() see http://php.net/manual/en/function.mysql-query.php您需要使用 mysql_query() 实际运行查询,请参阅http://php.net/manual/en/function.mysql-query.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.