Re: [GENERAL] PHP arrays and postgresql

From: "Gavin M(dot) Roy" <gmr(at)ehpg(dot)net>
To: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: [GENERAL] PHP arrays and postgresql
Date: 2004-01-07 22:02:51
Message-ID: 3FFC820B.3060202@ehpg.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-php


create table test(
t_value text;
);

$array_values[] = "Test 1";
$array_values[] = "Test 2";
$array_values[] = "Test 3";

pg_Query($conn, "INSERT INTO test VALUES ( '" .
base64_encode(seralize($array_values)) . "' );");

$result = pg_Query($conn, "SELECT * FROM test;");
$rows = pg_NumRows($result)
for ( $y = 0; $y < $rows; $y++ )
{
$data = unserialize(base64_decode(pg_Result($result, $y, 0)));
print_r($data);
}
pg_FreeResult($result);


Hope this helps (serialize, unserialize). I use base64_encode/decode to
ensure that there wont be any delimiter problems, could be achieved by
using addslashes as well.

Gavin

Mike Nolan wrote:

>This may not be the best place to ask the question, but I've already searched
>the PHP archive and code snippet sites.
>
>I'm trying to find a way to store and then retrieve a PHP array in
>my pg database.
>
>Has anyone written some code to do this?
>--
>Mike Nolan
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-01-07 22:15:59 Re: pg_stats question
Previous Message Richard Huxton 2004-01-07 21:59:32 Re: PHP arrays and postgresql

Browse pgsql-php by date

  From Date Subject
Next Message Mike Nolan 2004-01-08 00:23:03 Re: PHP arrays and postgresql
Previous Message Richard Huxton 2004-01-07 21:59:32 Re: PHP arrays and postgresql