try {
$db = new PDO('mysql:dbname=myDataBase', 'username', 'password');
}
catch (PDOException $e) {
die ($e->getMessage());
}
$query = $db->prepare('SELECT foo, bar, cad from myTable');
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);
$data = array(
'cols' => array(
// array of column definitions, eg:
array('type' => 'string', 'label' => 'Foo'),
array('type' => 'number', 'label' => 'Bar'),
array('type' => 'number', 'label' => 'Cad')
),
'rows' => array() // will contain the rows of data
);
foreach($results as $row) {
// add data to the row
$rows[] = array('c' => array(
array('v' => $row['foo']),
array('v' => $row['bar']),
array('v' => $row['cad'])
));
}
// when outputting your data, use
json_encode($data, JSON_NUMERIC_CHECK);