Mysql 查询:date_format 和 sprintf()

发布于 2024-11-04 07:18:33 字数 495 浏览 1 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手心的温暖 2024-11-11 07:18:33

您必须使用额外的 % 对日期格式字符串进行转义,请尝试以下操作:

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"));

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"));
小苏打饼 2024-11-11 07:18:33

您需要使用 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

野心澎湃 2024-11-11 07:18:33

在 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 个输入,这也应该有效)

In the sprintf string you have:

"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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文