Here's a basic PHP script to get you started (assuming you are querying MS SQL Server locally from a Windows-based PHP environment; there is a small change you have to make to use a non-windows based environment):
<?php
// $databaseName is the database to access
// $username is the user name to log in with
// $password is the user name's password for logging in
try {
$db = new PDO("mssql:dbname=$databaseName", $username, $password);
}
catch (PDOException $e) {
echo $e->getMessage();
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$queryStr = "SELECT foo, bar, baz FROM myTable WHERE cad = :cadValue";
$params['cadValue'] = $_GET['cad'];
$query = $db->prepare($queryStr);
$query->execute($params);
$results = $query->fetchAll(PDO::FETCH_ASSOC);
$table = array();
$table['cols'] = array(
// each element in this array is 1 column in the DataTable
// you must specify a type for each column, the label is optional
array('label' => 'foo', 'type' => 'string'),
array('label' => 'bar', 'type' => 'number'),
array('label' => 'baz', 'type' => 'number')
);
$rows = array();
foreach ($results as $row) {
$temp = array();
$temp[] = array('v' => $row['foo']);
// you may have to typecast values extraced from the database if they come out as strings, eg:
// typecast as floating point number:
$temp[] = array('v' => (float) $row['bar']);
// typecast as integer number:
$temp[] = array('v' => (int) $row['baz']);
$rows[] = array('c' => $temp);
}
// gracefully exit the database
$results = null;
$query = null;
$db = null;
$table['rows'] = $rows;
// 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($table);
?>
That script is set up to be used as an AJAX-based data source rather than populating the javascript directly, but it can be adapted for the latter case if you want.