From: Chris <chris@interspire.com>
To: 'Lynna Landstreet' <lynna@gallery44.org>
To: pgsql-php@postgresql.org
Subject: Re: Sessions and serializing (was: Checking data inserted
Date: Thu, 20 May 2004 12:46:54 +1000
Message-ID: <001c01c43e14$b69eb960$0d00a8c0@chris> (raw)
In-Reply-To: <BCD146A7.12C2%lynna@gallery44.org>
Hi Lynna,
on 5/12/04 7:36 PM, Chris at chris@interspire.com wrote:
> You could serialize up the data in sessions and then use that data
> before adding it to the database. See http://www.php.net/serialize and
> http://www.php.net/unserialize and http://www.php.net/session> OK, so if I understand this correctly, the serialize function can take
something like a big associative array containing all the data I want to
be able to write into the database and condense it into a single object
that can be passed via a hidden form field or something to that effect,
correct? Or the data can be put into the session array using $_SESSION,
and then passed by using a $session_id in the page URL?
You won't need to use unserialize and serialize per page if you're going
to use sessions - you only need those if you're going to pass the values
in a URL or in a hidden form field.
For sessions, you can simply
$my_array = array('1','2','3','4','5');
$_SESSION['blah'] = $my_array;
sort of thing..
> But according to one of the user comments in the manual I have to use
> addslashes() and stripslashes() if I want to be able to put the data
into the database after unserializing it - is that right?
Yep. So you'll need to do
$value = addslashes(serialize($real_value));
and use $value in your query...
Then when you fetch out
$real_value = unserialize(stripslashes($value));
Done =)
> Also, what about character encoding? My database and my web pages are
utf-8 because of the presence of special characters in some of the
artists and names and image and exhibition titles (it's a Canadian
gallery, so there are a lot of French artists). Will serializing the
array containing the data affect that in any way?
Not as far as I know, it should handle that fine.
> Sorry if I'm being a pest - the whole session thing is new to me and I
want to make sure I understand it correctly.
Ask as many questions as you need to, we've all been at the start before
=)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: chris@interspire.com, lynna@gallery44.org
Subject: Re: Sessions and serializing (was: Checking data inserted
In-Reply-To: <001c01c43e14$b69eb960$0d00a8c0@chris>
References: <BCD146A7.12C2%lynna@gallery44.org> <001c01c43e14$b69eb960$0d00a8c0@chris>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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