[ale] PHP Guru

David Tomaschik david at systemoverlord.com
Thu Jan 31 16:00:16 EST 2013


On Thu, Jan 31, 2013 at 10:44 AM, Chuck Payne <terrorpup at gmail.com> wrote:

> Guys,
>
> I need help from php guru.
>
> I have sql statement that works great in mysql, where I'm am using
> datediff. When I try to use it in php, I get an "mysql_fetch_arrary()
> expects parameter 1 to be a resource, boolean given in"
>
> This the statement is...
>
> $result = mysql_query("select hname, hsn, hmodel, hmake, htype, hwar,
> datediff(`hwar`, now()) from host where stype='physical';",$db);
>
>
The backticks within double quotes are being interpreted as the execution
operator: http://php.net/manual/en/language.operators.execution.php

Either remove them (fine since hwar is not a reserved word) or escape them.


> I know the statement works in 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 |
>
>
> When I remove datediff(`hwar`, now()), my page works.  I wanted to use
> that as field
>
> $datediff=$row['datediff'];
>
> Any clues as to why it doesn't work?
>
> --
> Terror PUP a.k.a
> Chuck "PUP" Payne
>


-- 
David Tomaschik
OpenPGP: 0x5DEA789B
http://systemoverlord.com
david at systemoverlord.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130131/734e5682/attachment.html>


More information about the Ale mailing list