This isn’t something I have time to do today, but for anyone else who comes across this problem, you can probably enable json_encodeto output numbers from active records with the following steps:
1) Modify the mysql/mysql_resultphp file to include the$field->numeric metadata attribute.
2) Add an extra step to active record queries that uses CodeIgniter’s $this->db->field_data() totest for any fields with numeric==1
3) If numeric==1, cast that field’s value to a number.
$retval = array();
while ($field = mysql_fetch_field($this->result_id))
$F = new stdClass();
$F->name = $field->name;
$F->type = $field->type;
$F->default = $field->def;
$F->max_length = $field->max_length;
$F->primary_key = $field->primary_key;
$F->numeric = $field->numeric; // <!-- ADD THIS LINE
$retval = $F;
Heavy reliance on JSON in my scenario might make the extra effortworthwhile, but most people might never run into this.
2、It’s a blunt wayto solve the problem, but “good enough” for me. The functioncomments are based on PHP’s settype() documentationat
Here’s an exampleof how to use it: