This is what I use (I use PDO's rather than PHP's mysql functions, but you can adapt this to your needs):
$query = $db->prepare($queryStr);
$query->execute($params);
$results = $query->fetchAll(PDO::FETCH_ASSOC);
// $cols is an array of MySQL column names mapped to DataTable type and label
foreach ($cols as $colKey => $col) {
if ($col['type'] == 'tooltip') {
$output['dataTable']['cols'][] = array ('type' => 'string', 'role' => 'tooltip', 'p' => array ('role' => 'tooltip'));
}
else {
$output['dataTable']['cols'][] = array ('type' => $col['type'], 'label' => $col['label']);
}
}
foreach ($results as $row) {
$temp = array ();
foreach ($cols as $colKey => $col) {
$temp[] = array('v' => ($col['type'] == 'number') ? (float) str_replace(',', '', $row[$colKey]) : $row[$colKey]);
}
$output['dataTable']['rows'][] = array ('c' => $temp);
}
$output['options'] = $setup['options'];
$output['chartType'] = $setup['chartType'];
// set up header and output json (first two prevent IE from caching queries)
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($output);