Welcome Guest, Not a member yet? Register   Sign In
Original data types in Active Record query result?
#3

[eluser]Samuel Wan[/eluser]
At first, I implemented a content revisioning feature, and didn't have any problems incrementing a revision_number column of type int, probably because PHP casts the Active Record's string value to int for arithmetic operations.

E.g.
Code:
$new_revision_number = $row->revision_number + 1; // no problem

However,the big scenario where this breaks down is JSON-encoded responses. Most of my controller actions are AJAX web service methods via that return JSON-encoded records in response to HTTP-POST requests. Security issues aside, my original plan was to write simple web service controllers like so:

Code:
class SomeController() {
...
function getLastRevisionNumber($id) {
   ...load model, run query...
   echo json_encode($query->row());
}
...
}

Instead of the expected result:
Code:
[1,2,3,4,5]

I get this:
Code:
["1","2","3","4","5"];

Unfortunately, I might need to move away from Code Igniter (or PHP entirely) because this scenario goes from very simple to very painful if I need to write hand-crafted transformations back to the original database column type for every requested record.

Are there any ORMs compatible with Code Igniter that might return original types? I'm new to PHP but I don't mind wrapping other frameworks into Libraries as I've already learned how to do that for PEAR.


Messages In This Thread
Original data types in Active Record query result? - by El Forum - 03-31-2009, 04:52 PM
Original data types in Active Record query result? - by El Forum - 03-31-2009, 05:23 PM
Original data types in Active Record query result? - by El Forum - 03-31-2009, 05:50 PM
Original data types in Active Record query result? - by El Forum - 03-31-2009, 06:49 PM
Original data types in Active Record query result? - by El Forum - 03-31-2009, 10:42 PM
Original data types in Active Record query result? - by El Forum - 04-01-2009, 04:30 AM
Original data types in Active Record query result? - by El Forum - 04-02-2009, 05:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB