我有sql语句在mysql中运行很好,我正在使用datediff。当我尝试在php中使用它时,我得到一个“mysql_fetch_arrary()期望参数1是一个资源,布尔值在”
中给出这句话是......
$result = mysql_query("select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) from host where stype='physical';",$db);
我知道该语句适用于mysql
mysql> select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) from servers.host where stype='physical';
+--------------+---------+--------+-----------+-------+------------+-------------------------+
| hname | hsn | hmodel | hmake | htype | hwar | datediff(`hwar`, now()) |
+--------------+---------+--------+-----------+-------+------------+-------------------------+
| moscow | XXXXXXX | Dell | PowerEdge | R710 | 2013-09-13 | 225 |
| sydney | XXXXXXX | Dell | PowerEdge | R710 | 2013-09-15 | 227 |
当我删除datediff(
hwar , now())
时,我的页面正常运行。我想将其用作字段
$datediff=$row['datediff'];
关于它为什么不起作用的任何线索?
答案 0 :(得分:0)
尝试在查询中设置限制
$result = mysql_query("select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) as dif from host where stype='physical' LIMIT 0,10 ;",$db);
答案 1 :(得分:0)
试试这个:
替换这段sql语句:datediff(hwar
,now())
使用:datediff(hwar
,now())作为Diffdate
以这种方式恢复: $ DATEDIFF = $行[ 'Diffdate'];
Bye XD
答案 2 :(得分:0)
您应该为选择器添加别名:
select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) AS diff from host where stype='physical';
然后您可以访问名为'diff'
的列