title: PHP PDO: how to return integer
body: <p>I think it might be a flaw in my pdo fetching data method,</p>
  
  <pre><code>public function fetch_all($query, $params = array())
      {
          try
          {
              # prepare the query
              $stmt = $this-&gt;connection-&gt;prepare($query);
  
              # if $params is not an array, let's make it array with one value of former $params
              if (!is_array($params)) $params = array($params);
  
              # execute the query
              $stmt-&gt;execute($params);
  
              # return the result
              return $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
          }
          catch (PDOException $e) 
          {
              # call the get_error function
              $this-&gt;get_error($e);
          }
      }
  </code></pre>
  
  <p>All the parameters that have been passed into this method will become strings, but I need integers for sql LIMIT query, such as below</p>
  
  <pre><code>$sql = "
      SELECT *
  
      FROM root_pages
      ORDER BY root_pages.pg_created DESC
  
      LIMIT ?,?";
  
  items = $connection-&gt;fetch_all($sql,array('0','6'));
  </code></pre>
  
  <p>It returns this error,</p>
  
  <blockquote>
    <p>2SQLSTATE[42000]: Syntax error or
    access violation: 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 ''0','6'' at line 32</p>
  </blockquote>
  
  <p>How can I fix it?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As suggested, I changed the code in my method to this below,</p>
  
  <pre><code># fetch a multiple rows of result as a nested array ( = multi-dimensional array)
      public function fetch_all($query, $params = array())
      {
          try
          {
              # prepare the query
              $stmt = $this-&gt;connection-&gt;prepare($query);
  
              # if $params is not an array, let's make it array with one value of former $params
              //if (!is_array($params)) $params = array($params);
  
  
              foreach($params as $k=&gt;$p){
                if(is_numeric($p)){
                  $stmt-&gt;bindParam($k+1, $p, PDO::PARAM_INT);
                }
                else{
                  $stmt-&gt;bindParam($k+1, $p, PDO::PARAM_STR);
                }
              }
              $stmt-&gt;execute();
  
  
              # execute the query
              //$stmt-&gt;execute($params);
  
              # return the result
              return $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
          }
          catch (PDOException $e) 
          {
              # call the get_error function
              $this-&gt;get_error($e);
          }
      }
  
  $items = $connection-&gt;fetch_all($sql,array(0,6));
  </code></pre>
  
  <p>then I get a different error,</p>
  
  <blockquote>
    <p>2SQLSTATE[42000]: Syntax error or
    access violation: 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 ''6'' at line 32</p>
  </blockquote>
  
  <p>EDIT:</p>
  
  <p>I just changed it to,</p>
  
  <pre><code>if(is_int($p)){..}
  </code></pre>
  
  <p>but still getting the same error... sigh...</p>