By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,745 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,745 IT Pros & Developers. It's quick & easy.

storing an array in a db

P: n/a
I know your first reaction will be "WHY?!?!" But can it be done? Can I store
a php array in a postgresql database?

--
Alexander Ross
al******@bleen.net
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 07 Aug 2003 17:51:37 GMT, "Alexander Ross"
<al******@bleen.net> wrote:
I know your first reaction will be "WHY?!?!" But can it be done? Can I store
a php array in a postgresql database?


Yes you can - but you'll have to explode the array first and put it
into a suitable data structure.

Still can't understand why though :)
Jul 16 '05 #2

P: n/a
Alexander Ross wrote:
I know your first reaction will be "WHY?!?!" But can it be done? Can I
store a php array in a postgresql database?


You can, given you store the data in a sensible fashion

e.g.

$storeary = array();
foreach ($myarray as $myval)
{
$storeary[] = urlencode($myval);
}
$storestr = join('=', $storeary);

on retrieval, you can explode('=', $retstr) and urldecode the values

Alternatively, you could just have a separate table to store the array
values in. It depends on what suits your application best
Jul 16 '05 #3

P: n/a
Hi Kafooey!

On Thu, 07 Aug 2003 18:10:00 GMT, kafooey <ka*****@yahoo.co.uk> wrote:
On Thu, 07 Aug 2003 17:51:37 GMT, "Alexander Ross"
<al******@bleen.net> wrote:
I know your first reaction will be "WHY?!?!" But can it be done? Can I store
a php array in a postgresql database?
Yes you can - but you'll have to explode the array first and put it
into a suitable data structure.

I would rather suggest to store it as a serialized object.Still can't understand why though :)


Example: i have a set of classes (see signature) that provide an easy
edit interface to any amount of tables. Also, it creates a "filter
block", where the user can filter by criteria on table fields.

If I wanted to add saveable filters, I would store them as an array of
the filter-criteria, serialized. This means I can have one table for
saved filters, not as many as I have tables.

HTh, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.