title: Convert MySQL record set to JSON string in PHP
body: <p>Is there a function or class in PHP that I can pass a MySQL recordset and I get a JSON string returned that can be passed back to a JavaScript function in an Ajax request?</p>
  
  <p>something like this:</p>
  
  <pre><code>function recordSetToJson($recordset) {
   while($rs1 = mysql_fetch_row($recordset)) {
    for($count = 0; $count &lt; count($rs1); $count++) {
     //  read and add field to JSON
    }
    $count++;
   }
  
   return $jasonstring
  }
  </code></pre>