title: SQL query returns empty result
body: <p>I have this SQL query:</p>
  
  <pre><code>SET @date_shift = DATE_SUB(NOW(), Interval 60 MINUTE);
  SELECT hinfo.idx,
     hinfo.host_idx,
     hinfo.processor_load,
     hinfo.memory_total,
     hinfo.memory_free,
     hnames.idx,
     hnames.name,
     disks.hostinfo_idx,
     disks.id,
     disks.name,
     disks.size,
     disks.freespace,
     hinfo.probetime
  FROM   systeminfo.hostinfo AS hinfo
     INNER JOIN systeminfo.hosts AS hnames
             ON hnames.idx = hinfo.host_idx
     INNER JOIN systeminfo.disksinfo AS disks
             ON disks.hostinfo_idx = hinfo.idx
  WHERE   hinfo.probetime &gt; @date_shift AND
        hinfo.probetime = (SELECT MAX(probetime) FROM systeminfo.hostinfo AS hi
                                      WHERE hi.probetime &gt; @date_shift AND hi.host_idx = hinfo.host_idx)
  GROUP  BY disks.id,
        hnames.name
  ORDER  BY hnames.name,
        disks.id;
  </code></pre>
  
  <p>and i try to execute it in php code. I tried mysql, mysqli and pdo. Ma last code is following:</p>
  
  <pre><code>$db = new PDO("mysql:host=".$this-&gt;ip.";dbname=".$this-&gt;dbname.";charset=utf8", $this-&gt;username, $this-&gt;password);
  $result = $db-&gt;query($query);
  $fetch_data = $result-&gt;fetchAll(PDO::FETCH_ASSOC);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>mysql_connect($this-&gt;ip, $this-&gt;username, $this-&gt;password);
  mysql_query('SET NAMES utf8;');
  mysql_select_db($this-&gt;dbname);
  $result = mysql_query($query);
  </code></pre>
  
  <p>PHP connects correcly to the database. Simple queries, like select * from tablename works. But this query returns NO data but error:</p>
  
  <blockquote>
    <p>1064 : You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 'SELECT hinfo.idx, hinfo.host_idx, hinfo.processor_load,
    hinfo.memory_total, ' at line 2</p>
  </blockquote>
  
  <p>The same query, executed in the database client works perfectly (it's not a slow query, it takes less than 10 ms to perform it).
  Moreover, when i try to print the query directly from this function on a web page and paste it into mysql client - it works perfectly as well! I can't find any special character in hex viewer i tried to force utf-encoding, nothing.</p>
  
  <p>Any ideas? Test i could perform? Thanks in advance!</p>