Connecting Tech Pros Worldwide Forums | Help | Site Map

storing an array in a db

Alexander Ross
Guest
 
Posts: n/a
#1: Jul 17 '05
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
alexross@bleen.net


kafooey
Guest
 
Posts: n/a
#2: Jul 17 '05

re: storing an array in a db


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

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 :)
matty
Guest
 
Posts: n/a
#3: Jul 17 '05

re: storing an array in a db


Alexander Ross wrote:
[color=blue]
> I know your first reaction will be "WHY?!?!" But can it be done? Can I
> store a php array in a postgresql database?
>[/color]

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
Jochen Daum
Guest
 
Posts: n/a
#4: Jul 17 '05

re: storing an array in a db


Hi Kafooey!

On Thu, 07 Aug 2003 18:10:00 GMT, kafooey <kafooey@yahoo.co.uk> wrote:
[color=blue]
>On Thu, 07 Aug 2003 17:51:37 GMT, "Alexander Ross"
><alexross@bleen.net> wrote:
>[color=green]
>>I know your first reaction will be "WHY?!?!" But can it be done? Can I store
>>a php array in a postgresql database?[/color]
>
>Yes you can - but you'll have to explode the array first and put it
>into a suitable data structure.
>[/color]
I would rather suggest to store it as a serialized object.[color=blue]
>Still can't understand why though :)[/color]

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/
Closed Thread