title: PHP PDO: SQL query not returning expected result
body: <p>I have a function (see bottom) in PHP, which queries a MySQL database. 
  When I use the following values:</p>
  
  <ul>
  <li>$map => 1,</li>
  <li>$limit => 10, </li>
  <li>$from => 0, </li>
  <li>$to => CURRENT_TIMESTAMP</li>
  </ul>
  
  <p>With the SQL statement:</p>
  
  <pre><code>SELECT user,
         scoreVal AS score,
         UNIX_TIMESTAMP(timestamp) AS timestamp 
    FROM Score 
   WHERE timestamp &gt;= :from 
     AND timestamp &lt;= :to 
     AND map = :map 
   ORDER BY scoreVal DESC, timestamp ASC 
   LIMIT :limit
  </code></pre>
  
  <p>In phpMyAdmin, I get the following result:</p>
  
  <p><a href="https://i.stack.imgur.com/N1LkZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N1LkZ.png" alt="phpMyAdmin result"></a></p>
  
  <p>However the PHP PDO gets returned an empty array.</p>
  
  <p>My attempts to debug so far:</p>
  
  <ul>
  <li>I have replaced he prepared SQL query with static values instead of placeholders - Returns correctly</li>
  <li>Trying each placeholder separately, replacing the rest with tested hard-coded values - Returns nothing</li>
  <li>Instead of passing variables to placeholders I pass fixed constants in the execute(Array()) part. - Returns nothing.</li>
  <li>I have furthermore discovered after turning on mySQL query logs, that the PHP client Connects, but then quits without sending any queries.</li>
  </ul>
  
  <p>From this, I believe it to be a problem with the place holders within the function, however I have been unable to find a reason why they are failing. This is most probably occurring on the PHP side, as no errors are being thrown by MySQL to the error file.</p>
  
  <p>This is the function I am using, with the variables being passed in:</p>
  
  <ul>
  <li>$map => 1,</li>
  <li>$limit => 10, </li>
  <li>$from => 0, </li>
  <li>$to => 0</li>
  </ul>
  
  <p>Function:</p>
  
  <pre><code>/**
   * Gets the highscore list for the map in that timespan
   * @param  integer $map   Id of map for which to fetch the highscore
   * @param  integer $limit Maximum no. of records to fetch
   * @param  integer $from  Timestamp from when to find rank
   * @param  integer $to    Timestamp up to when to find rank
   * @return array   Array of highscores arranged by rank for the map in the format [{"user"=&gt;$user,"score"=&gt;score,"timestamp" =&gt; timestamp}]
   */
  function get_highscore_list($map,$limit,$from,$to){
      $sql = "SELECT user,scoreVal AS score,UNIX_TIMESTAMP(timestamp) AS timestamp FROM Score WHERE timestamp &gt;= :from AND timestamp &lt;= :to AND map = :map ORDER BY scoreVal DESC, timestamp ASC LIMIT :limit";
      if ($to==intval(0)){
          $max =1;
          $sql = str_replace(":to","NOW()",$sql,$max);
      }
      try{
      $conn = request_connection();
      $stmt = $conn-&gt;prepare($sql);
      $stmt-&gt;execute(array(':map'=&gt;$map,':from'=&gt;$from,':limit'=&gt;$limit));
      $result = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      }catch(PDOException $e){
          $_POST["exception"]=$e;
          continue;
      }
      return $result;
  }
  </code></pre>
  
  <p>EDITS</p>
  
  <hr>
  
  <p>Format of MySQL table:</p>
  
  <p><a href="https://i.stack.imgur.com/Z7peR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z7peR.png" alt="MySQL table format"></a></p>
  
  <hr>
  
  <p>I have tried outputting the $conn->errorInfo();, however as no error is being thrown, I get returned an array of values:
  [00000,null,null]</p>
  
  <hr>
  
  <p>The request_connection function only returns the result of this function, and it is working for all of my other statements. </p>
  
  <pre><code>/**
   * Creates a new PDO connection to the database specified in the configuration file
   * @author Ignacy Debicki
   * @return PDO A new open PDO connection to the database
   */
  function create_connection(){
      try {
          $config = parse_ini_file('caDB.ini');
          $conn = new PDO('mysql' . ':host=' . $config['dbHost'] . ';dbname=' . $config['db'],$config['dbPHPUser'], $config['dbPHPPass']);
          date_default_timezone_set($config['dbTimezone']);
          return $conn;
      } catch(PDOException $e){
          throw new Exception("Failed to initiate connection",102,$e);
      }   
  }
  </code></pre>
  
  <p>Thanks</p>