Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Getting a record associative array from a record set

posted by nk27 9 years ago

I'm giving a try to Flourish -a very nice no-framework!- and I have started with all the database issues. I have no problem getting a fRecordSet object with fRecordSet::build, extracting a record from it with fetchRecord() or getting some field value from that record, let us say with getEmail(). However, I've been unable to get an associative array iterating all fields and values of a record without having to get each one separately. I suppose I could get it in a more standard way using fResult methods, but I'm figuring whether I could get that associative array from a fRecordSet, as well. I have not found any information about that in the docs or in previous threads in this forum.

Thanks in advance.

Well, it seems it's solved. Looking in depth the object dump I see that all values are protected. Surely this is a rule for Flourish, so I have added a public getAsArray() method to my class, so I can call it to get an array with all the properties and their values as name => value pairs.

Thanks for such a great development library!

posted by nk27 9 years ago

Yes, in general with Flourish I try to keep as much information private or protected because it allows me to refactor code without breaking backwards compatibility. That said, the $values array in fActiveRecord should be pretty stable. I don't believe I've change it since I started Flourish. If there were any breaks with it, it would be listed on the InternalBackwardsCompatibilityBreak page.

I'm curious just because I try to make the API intuitive, but robust for what purpose did you want the raw array of values? Are you just used to using array syntax to retrieve information, or did you want to use array functions on it?

posted by wbond 9 years ago

Yes, it is only that I'm used to array syntax. Currently I'm only testing Flourish, so I was a bit uncomfortable at the beginning, but no problem to start being used to this model :-)

posted by nk27 9 years ago