Skip to content

Instantly share code, notes, and snippets.

@dvidsilva
Created September 30, 2012 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvidsilva/3806154 to your computer and use it in GitHub Desktop.
Save dvidsilva/3806154 to your computer and use it in GitHub Desktop.
Returns the result of a query as an array
//receives a query and returns an array in the following format
// array['row-number']['field_name'] = 'value'
function q2ar($query){
$query = $this->mysql($query);
$n=0;
$data = '';
if(is_resource($query)){
while($row = mysql_fetch_row($query) ){
$i=0;
while ($i < mysql_num_fields($query)){
$meta = mysql_fetch_field($query, $i);
$data[$n][$meta->name] = $row[$i];
$i++;
}
$n++;
}
return ($data);
}else{
return (false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment