我想在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”
Plz帮助
答案 0 :(得分:9)
你必须使用额外的%'来转义日期格式字符串,试试这个:
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"));
答案 1 :(得分:0)
在sprintf字符串中,您有:
"SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'),
timeofevent, location, details, presenter,
bio FROM events WHERE eventid = %s"
其中有5
个输入,但您只输入一个(GetSQLValueString($colname_eventeditrs, "int")
),另外输入4个并且您应该是金色的(或者在评论中如下所述) ,逃脱4输入,这也应该工作)
答案 2 :(得分:-1)
您需要使用mysql_query()实际运行查询,请参阅http://php.net/manual/en/function.mysql-query.php