title: PHP MySql -- return all records where column names are unknown
body: <p>I am writing a web service for use in a mobile application. The web service uses a support class that executes a query and returns the results as JSON. I would like to be able to simple return the entire result set as JSON, but "mysql_fetch_array" only returns one record at a time. Furthermore, I will not know the column names, so manually generating the JSON output could be tricky. </p>
  
  <p>So I guess this is a two part question. In .NET, there is a columns collection through which the column names can be acquired. Is there anything like this in PHP? And, how would one return the entire result set as JSON without having to iterate the set and manually build the JSON. THanks! Viv</p>
  
  <pre><code>    public static final function executeSelectQuery($qry){
          $connection = mysql_connect(ADS_DB_HOST, ADS_DB_USERNAME, ADS_DB_PASSWORD) or die(ADS_ERROR_MSG . mysql_error());
          $db = mysql_select_db(ADS_DB_NAME) or die(ADS_ERROR_MSG . mysql_error());
          $result = mysql_query($qry) or die(ADS_ERROR_MSG . mysql_error());
          mysql_close();
  
          while($rows = mysql_fetch_array(($result))){
              // how do I access column names?
          }
      }
  </code></pre>