fetchStyle in Editor server-side Result class
fetchStyle in Editor server-side Result class
csdatum
Posts: 30Questions: 10Answers: 0
There is currently no way to specify which fetch style to use in a sql query. A simple argument would be a very easy addition to the Results class. Something like this would work well:
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
How would you handle all the errors arising from bad "fetch styles" being submitted?
I think documenting that it must be a PDO::fetch_* constant would be sufficient since it is simply passing it through to the fetch() and fetchAll() functions.
Alternatively, some sort of Result->getStatement() function could be provided so users can get data in whatever style they like.
The Editor libraries assume FETCH_ASSOC which is why it is specified that way in the drivers. I don't really see a problem with the suggestion you make though since it wouldn't effect anything in Editor (I presume you are making use of the Database classes external to Editor?).
Allan
Thank you for the response, yes that's correct. I wrote a couple of functions that use the database classes to apply some extra joins and where clauses as Editor fetches data. I'm trying to re-use those functions for different things apart from Editor, and having the ability to specify a fetch style would be very useful.
I've done that now and it will be in Editor 1.7.4 - you simply pass the PDO fetch type you want into the
Result->fetch()
orResult->fetchAll()
method.Worth noting that the Oracle and Db2 integrations in the PHP libraries don't use PDO so they won't work there.
Allan