title: MySQL how to store FOUND_ROWS() in a PHP variable
body: <p>I'm trying to get the total number of rows returned by my query before I limit it. I'm attempting to use the advice found <a href="https://stackoverflow.com/questions/2229218/what-is-mysql-version-of-rowcount">here</a>, which uses: <code>SQL_CALC_FOUND_ROWS</code> and then <code>FOUND_ROWS()</code> in a second query;</p>
  
  <p>They give this example:</p>
  
  <pre><code>SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever;
  SELECT FOUND_ROWS( ) ;
  </code></pre>
  
  <p>What I can't figure out is how to capture the second value from <code>FOUND_ROWS()</code> into a PHP variable. I'm working within Wordpress, so I'm using the global $wpdb to handle MySQL interactions. Here's a simplified version of what I'm trying:</p>
  
  <pre><code>$rows = $wpdb-&gt;get_results( "SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever;" );
  $count = $wpdb-&gt;get_results( "SELECT FOUND_ROWS();" );
  </code></pre>
  
  <p>The first query works, but $count is always empty. If I run them both in phpMyAdmin, the queries run without error. </p>
  
  <p>I've also tried this:</p>
  
  <pre><code>$rows = $wpdb-&gt;get_results( "SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever;
  SET @count = FOUND_ROWS();" );
  </code></pre>
  
  <p>...but it fails entirely.</p>
  
  <p>What am I doing wrong?</p>