我创建了一个在phpmyadmin上完美运行的查询
SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%d-%m-%y') as horo FROM userlogin WHERE type='user' ORDER BY horo DESC
但当我在PHP上传递此查询时返回错误为query was empty
我的PHP代码是
$selectorders=sprintf("SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%d-%m-%y') as hor FROM userlogin WHERE type='user' ORDER BY horo DESC");
$myorderquery = mysql_query($selectorders) or die(mysql_error());
$row_rsselect = mysql_fetch_assoc($myorderquery);
答案 0 :(得分:2)
您无缘无故地使用sprintf
。由于您的日期格式使用'%'如果你想要使用这个功能,你需要加倍它们:
$selectorders=sprintf("SELECT *,STR_TO_DATE(horoaccess_validity_enddate , '%%d-%%m-%%y') as hor FROM userlogin WHERE type='user' ORDER BY horo DESC");
只需使用字符串声明即可。