I have an sql view which returns over 10,000 records with about 120 columns (ridiculous, I know).
The view data is gathered from the database in PHP using a Zend_Db_Table_Abstract object. We have a report controller which does a fetchAll (which obviously creates a massive array) and stores the array in a view object. Next we have a view script which iterates over the array and echoes a json formatted array.
This is slowwww. Like over 1 minute to render this report, what can I do to speed this up?
Bare in mind I am very new to this project and have no knowledge of Zend and little of PHP. Also I can't give away to much due to data protection etc.
If you could ask what you need to help you gather the picture that would be great. But basically this is what the script does:
Report controller:
Setup some basic json report data (for data tables)
$this->view->report_data = fetchALL($oSelect);
View script:
Output the basic json stuff, then:
"report_data": [
<?php
for($i = 0; $i < count($this->report_data); $i++){
echo "[";
foreach($this->columns as $k=>$col){
echo '"'. $this->escape($this->report_data[$i][$col]) .'"';
if($k < count($this->columns) -1 ){
echo ',';
}
}
echo "]";
if($i < count($this->report_data) -1){
echo ",";
}
echo"\n";
}
?> ]
So after doing some research I gathered that I could use fetch() instead of fetchAll() so to get 1 row at a time, to avoid the massive array. However I tried to use the fetch() and got this error:
Call to undefined method Zend_Db_Table_Abstract::fetch()
So now I'm bummed.
My idea was to get each row and output each row Json formatted, however I don't really know how I would do this in the report controller/ view scenario. Would I have to just get rid of the view script and just use the controller to output the data?
Anyway why does fetch() not work, I can't actually see it in the docs either, well there is some array function _fetch()
Any help would be appreciated, any if you need more info just ask. Thanks