Loading Data to grid faster

Hello, I have tried to load 2600 rows to grid.

  1. using connector
    include (“…/…/codebase/connector/grid_connector.php”);
    include (“…/…/codebase/connector/db_pdo.php”);
    $user_data = new GridConnector($dbconn, “PDO”);
    $query = “select nip,nama,alamat from pegawai”;
    $user_data->render_sql($query, “nip”, "nip, nama, alamat ");

  2. using manual way like written on docs
    header ("Content-Type: text/xml; charset=ISO-8859-1 ");
    if( strpos($_SERVER[“HTTP_ACCEPT_ENCODING”],“gzip”) !== FALSE){
    } else {

         $posStart = $_GET['posStart'];
         $posStart = 0;
         $count = $_GET['count'];
         $count = 2600;
     $sql = "SELECT nip,nama,alamat FROM pegawai";
         $result = $dbconn->prepare($sql);
         $totalCount = $result->rowCount();
     $sql.= " LIMIT ".$posStart.",".$count;
     $result = $dbconn->prepare($sql);
     //output data in XML format   
     print("<rows total_count='".$totalCount."' pos='".$posStart."'>");   
     while($row = $result->fetch(PDO::FETCH_ASSOC)) {
         print("<row id='".$row['nip']."'>");
                 print($row['nip']);  //value for column1
                 print($row['nama']);  //value for column2
                 print($row['alamat']);    //value for column3


I have tried running these scripts at 2 web hosting, using firebug I got xml file size generated by php :
1.by connector 473kb
2.manual way 79kb (I think this will be faster because xml size smaller)

gzip compression disable by default at web hosting, so I came with this idea using ob_gzhandler

my question : If I want to using ob_start(“ob_gzhandler”) with connector, where I must put this line

Thank you

Note: Attachment image when trying at localhost

You can place the next before render_sql command

function my_output($out){ $text = (string)$out; echo $text; die(); } $user_data->event->attach("beforeOutput", $my_output);

$text here is the output of connector, so you can pre-process and output it as you wish.

Copying your script, I got error:
$user_data->event->attach(“beforeOutput”, $my_output); --> Undefined $my_output
change to:
$user_data->event->attach(“beforeOutput”, my_output); --> Object of class GridConnector could not be converted to string

Sorry, was a typo from my side, the valid code will look like next

function my_output($grid, $out){ $text = (string)$out; echo $text; die(); } $user_data->event->attach("beforeOutput", "my_output");

Thank you Stanislav,
using this method I got file size decreased after placing ob_gzhandler before echo $text, but encounter 2 problems

1.no xml output, if I use this grid.load(“filename.php”) data not going to inside grid, but alerting to messagebox
2. If I want to catch error with putting $user_data->event->attach(“OnDBError”, doOnDBError);
I got Content Encoding Error

You need to output XML header

header("Content-type: text/xml"); //mandatory echo('<?xml version="1.0"?>'); //optional echo $text;

Solved the problem,
but when I placing attach(“OnDBError”, doOnDBError), I got Notice error: Use of undefined constant doOnDBError.

Where I must put attach(“OnDBError”, doOnDBError),
because without attach(“beforeOutput”, “my_output”), the script running properly

function doOnDBError($action, PDOException $ex) {
$error_message = $ex->getMessage();


function my_output($grid, $out){
$text = (string)$out;
header ("Content-Type: text/xml; charset=ISO-8859-1 ");
echo $text;

$user_data->event->attach("beforeOutput", "my_output");
//$user_data->event->attach("OnDBError", doOnDBError);

You need to use something like next\

[code]function doOnDBError($action, PDOException $ex) {
$error_message = $ex->getMessage();


$grid->event->attach(“OnDBError”, “doOnDBError”);[/code]

  • place the method body BEFORE the attach call
  • surround method name in double quotes

Thank you very much Stanislav, I don’t know method name must placed inside double quotes
Because I see without double quotes in this doc
docs.dhtmlx.com/connector__php__ … event.html like this :

function doOnDBError($action, $exception){

It is based on the PHP error reporting settings.

With default one it must work with or without double quotes. In your case PHP configure in a bit more strict mode, so it is mandatory to use quotes