Welcome Guest, Not a member yet? Register   Sign In
Native data types from MySQL - should be possible
#5

It's a little odd that this particular setting seems to have the effect you're looking for. The third-party library mentioned passes the data through specific functions for specific types, returning the data in a format which may be more consistent with conversion to JSON, but is not necessarily closer to the native types (maybe PDO is mangling the type information without this setting, I don't really know, but in that case MySQLi should have worked).

JSON has never specified a date format, so different JavaScript libraries may implement them in different ways (though more recent versions of JavaScript include a toJSON() method on Date, giving a format to prefer in libraries which are aware of this format). While JavaScript's Date.toJSON() returns dates in an ISO-8601-formatted string, MySQL does not use this format for DATETIME or TIMESTAMP values (the DATE format happens to conform to this standard, but that probably was coincidental).

Because of that coincidence, passing MySQL dates through the date() function in your select statement does tend to make them conform for many JavaScript libraries, though you lose your time on DATETIME values (and TIMESTAMP values usually have to be passed through a different function). Using date_format(date, {format_string}) is usually the best option for getting the correct format directly from the database when using MySQL.
Reply


Messages In This Thread
RE: Native data types from MySQL - should be possible - by mwhitney - 03-17-2015, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB