storing an array in a db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Ross

    storing an array in a db

    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

    #2
    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 :)

    Comment

    • matty

      #3
      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($myva l);
      }
      $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

      Comment

      • Jochen Daum

        #4
        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@blee n.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.
        Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

        Comment

        Working...