My issue is that I am trying to get the columns from a mysql query using $query->list_fields().
I have a local Windows x64 machine and need have been using PHP 5.4 and everything works fine I have had not issues. I then moved over to the server which is LINUX centOS and none of the columns are pulled back at the database call. I have replicated the scenario issue on my local machine as best as I can and it pulls back the fields with no issue on my local machine. The weird thing is that I have a piece of code that pulls back the fields and puts it into an array for me and it works for a different call but not the one I want. I have validated the sql call and it returns a single result which is what I want and I have validated this.
Here are the specs:
| Client | Server
------|--------------------------|-----------------------------
OS | Windows x64 Professional| CentOS release 6.4 (Final)
Apache| Apache/2.4.4 | 2.2.24
MYSQL | 5.5.32 | 5.5.33
PHP | 5.4.16 | 5.4
The server I am using is a a hostgator shared plan
Here is the php code:
private function get_single_result_from_single_row_query(&$table, &$id, &$id_var = 'id')
{
$query = $this->db->limit(1)->get_where($table, array($id_var => $id));
if ($query->num_rows === 1)
{
$rows = ($query->result_object());
$cols = $this->get_collumns_as_array($query);
return $this->table_object_from_cols($cols, $rows[0]);
}
else
{
return NULL;
}
}
private function get_collumns_as_array(&$query)
{
$collumns = array();
foreach ($query->list_fields() as $field)
{
log_message('error', 'col field: '. $field);
array_push($collumns, $field);
}
if(empty($collumns))
{
log_message('error', 'collumns is empty'. $field);
}
return $collumns;
}
private function table_object_from_cols(&$collumns, &$row)
{
if ($collumns == NULL || empty($collumns))
{
return NULL;
}
$table_object = array();
foreach ($collumns as $col)
{
log_message('error', 'row->col : ' . $row->$col);
$table_object[$col] = $row->$col;
}
return $table_object;
}
As you can see I have pumped out an error when there are no columns to try as to best ascertain why! And also as should be seen is that the query can only go forward is the number of rows is equal to 1
Due to my plan I can not remotely debug the server apparently
Basically I am completely stumped all helps is soooooo appreciated
EDIT: I have tried removing the '&' from my functions and it has made no difference EDIT: I am now using PHP 5.4 on the server