pg.ddx.io pgsql-php@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Question about array datatype, and alternatives 2+ messages / 2 participants [nested] [flat]
* Question about array datatype, and alternatives @ 2007-05-09 05:04 Lynna Landstreet <lynna@spidersilk.net> 2007-05-09 12:26 ` Re: Question about array datatype, and alternatives John DeSoi <desoi@pgedit.com> 0 siblings, 1 reply; 2+ messages in thread From: Lynna Landstreet @ 2007-05-09 05:04 UTC (permalink / raw) To: pgsql-php Hi there, I've run into a sticky situation with a site I'm working on. The site uses an external payment gateway, and when a user has paid their membership fee there, it routes them back to a registration form on the site, where they can enter in their membership information, then saves it all into the database when the form is submitted. Now, the payment gateway returns a variety of information as a $_POST array when it sends them back, which I had some PHP code on the membership form capture and save into a subarray within $_SESSION, and then the script that processes the form takes that subarray and turns it into an insert statement which inserts the data the gateway returned into a database table set up for that purpose, so that we have all the sales data for each member (don't worry, this does *not* include credit card numbers or anything like that... it's more administrative stuff). The problem is that twice now, the information sent back by the gateway has changed, breaking my registration system. The first time, they added several new fields to the array it returned, so I amended the code that captures the information to only take the fields it had corresponding columns for in the table it eventually writes it to. Now, it's just failed again, and while I haven't checked to see exactly what they're returning now, it looks as though they either deleted some fields or changed their names, causing the insert to fail. It would be easy to set up a test page to see what they're now sending back with each transaction, but the thing is, if it's changed twice already, there's no reason to think it won't change further. So I'm looking for a way to store the array that it returns in a way that won't break if it suddenly has a different number of elements than usual, or changes the names of some of the keys. My first thought was that I could use the much-maligned array datatype, and just dump the entire array they send back into one column. But having looked through the documentation on that datatype, I'm not so sure that would work for an array of uncertain size. It looks as though it's meant to handle arrays that are a little more predictable in their composition. Now, phpPgAdmin does list a datatype called "anyarray", which according to the documentation is a "polymorphous" datatype that can handle almost anything, but there isn't a lot of detail on how to use that. PostgreSQL's array syntax seems to be very different from PHP's, and I don't know if it's really feasible to just dump the entire contents of a PHP associative array into an anyarray column. So then I thought of just serializing the array to result in a single string - would that work better? Does anyone have any experience with either array/anyarray columns, or any other way of storing incoming arrays with an uncertain number and variety of elements in PostgreSQL? Lynna -- Spider Silk Design - http://www.spidersilk.net 509 St Clair W Box 73576, Toronto ON Canada M6C 1C0 Tel 416.651.2899 - Cel 416.873.9289 ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Question about array datatype, and alternatives 2007-05-09 05:04 Question about array datatype, and alternatives Lynna Landstreet <lynna@spidersilk.net> @ 2007-05-09 12:26 ` John DeSoi <desoi@pgedit.com> 0 siblings, 0 replies; 2+ messages in thread From: John DeSoi @ 2007-05-09 12:26 UTC (permalink / raw) To: Lynna Landstreet <lynna@spidersilk.net>; +Cc: pgsql-php On May 9, 2007, at 1:04 AM, Lynna Landstreet wrote: > My first thought was that I could use the much-maligned array > datatype, and > just dump the entire array they send back into one column. But > having looked > through the documentation on that datatype, I'm not so sure that > would work > for an array of uncertain size. It looks as though it's meant to > handle > arrays that are a little more predictable in their composition. Now, > phpPgAdmin does list a datatype called "anyarray", which according > to the > documentation is a "polymorphous" datatype that can handle almost > anything, > but there isn't a lot of detail on how to use that. PostgreSQL's array > syntax seems to be very different from PHP's, and I don't know if it's > really feasible to just dump the entire contents of a PHP > associative array > into an anyarray column. I think you might have misread misread the documentation. You don't have to declare the size of the array in your schema specification (e.g. you can declare a column as text[] or text[][]). The catch to using arrays is that they don't map directly from PHP to PostgreSQL. So you have to write a small amount of code to format your PHP array as a PostgreSQL array string. > > So then I thought of just serializing the array to result in a > single string > - would that work better? A PostgreSQL array might be better if you plan to query the data or use it in some way outside of PHP. If you only intend to use the value in PHP, it is much easier to serialize it and stuff it in a text column. John John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-05-09 12:26 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2007-05-09 05:04 Question about array datatype, and alternatives Lynna Landstreet <lynna@spidersilk.net> 2007-05-09 12:26 ` John DeSoi <desoi@pgedit.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox