With a relative novelty to AJAX, and now, just starting to learn PDO, the added level of ReSTler completely clogs me. While modeling the code below from Restler samples, I donβt know how to change the output format from which PDO returns to what Retler and Highcharts expects.
How can I change this code to get from the current format to the required format? (Results will typically be 5K-10K entries if this is a factor in processing the MySQL result.)
ReSTler API code snippet :
$sql = "SELECT ....." $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $stmt = $this->db->query($sql); return $stmt->fetchAll(); } catch (PDOException $e) { throw new RestException(502, 'Listing History: ' . $e->getMessage()); }
Current output format (includes unwanted column names):
[ { "chart_date": "1118966400000", "bandwidth": "10.01", "views": "101" }, { "chart_date": "1119225600000", "bandwidth": "20.02", "views": "101" },
The format of the required output (numeric and without column names):
[ [ 1118966400000, 10.01, 101 ], [ 1119225600000, 20.02, 202 ],
Edit using suggested fetch(PDO::FETCH_NUM)
:
In response from @Ricardo Lohmann, I tried fetch (PDO :: FETCH_NUM), which DID removes the column names, but all the returned columns seem to be string rather than numeric, since there really is data, so try this by giving me the correct data type - Is this part of PDO for one-way row return?
while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $array[$x][0] = intval( $row[0] ); $array[$x][1] = intval( $row[1] ); $array[$x][2] = intval( $row[2] ); $x++; } return $array;