db_select doesnt work with me
You set incorrect semicolon at the end, remove it: while($data = $result-&gt;fetchAssoc());

And next manner looks more clear, instead using while:

foreach($result as $data) {
    $rows[] = array(
        $data-&gt;user_company_uid,
        $data-&gt;user_company_nid,
        $data-&gt;user_company_sub_number,
        $data-&gt;user_company_date,
    );
}