开发者

Mysql query : date_format and sprintf()

开发者 https://www.devze.com 2023-03-02 04:56 出处:网络
I want to use sprintf() along with date_format in a MySQL query. Here is query: mysql_select_db($database_exdb, $expdb);

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'), timeofe开发者_如何学Pythonvent, 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"));


You need to actually run the query using mysql_query() see http://php.net/manual/en/function.mysql-query.php


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消