Обсуждение: transactions?

Поиск
Список
Период
Сортировка

transactions?

От
Zhidian Du
Дата:
I am writing a B/S program.  I want to save all the users' inputs, for
example, "insert into TABLE value (.....);"  in the server side, how can
I implement in PHP?

also,  how can I use transactions to rollback and commit in PHP?

Re: transactions?

От
Justin Clift
Дата:
Hi Zhidian,

How far have you gotten?

For example, have you used databases with PHP before?  PostgreSQL has a
group of functions in PHP, and generally the first one you use is the
pg_pconnect() function, with some parameters to tell it how to connect,
where to, etc.

Then you can do stuff like execute queries against a database you've
already prepared, and so forth.

When actually inserting user data, if you need to keep it "as is" but
you'd like to be able to display it back at some point, I reckon you'll
be interested in the rawurlencode() and rawurldecode() functions.
Generally when I code stuff the very first thing that happens is that
all external input is made "safe" with rawurlencode() and that's how it
gets used internally from there on, that's how it gets stored, etc.  The
only time it gets rawurldecode()'d is as part of an echo string back to
the outside world.

Does that help?

:-)

Regards and best wishes,

Justin Clift


Zhidian Du wrote:
>
> I am writing a B/S program.  I want to save all the users' inputs, for
> example, "insert into TABLE value (.....);"  in the server side, how can
> I implement in PHP?
>
> also,  how can I use transactions to rollback and commit in PHP?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

--
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
   - Indira Gandhi

Re: transactions?

От
Harry Waddell
Дата:
>
> Zhidian Du wrote:
> >
> > I am writing a B/S program.  I want to save all the users' inputs, for
> > example, "insert into TABLE value (.....);"  in the server side, how can
> > I implement in PHP?
> >
> > also,  how can I use transactions to rollback and commit in PHP?
> >

I use these functions to start, stop and abort transactions.
[although most people would find it silly to wrap a single line of code with
another function. I have my reasons.]

Function begin_work($pg){
  pg_FreeResult(pg_Exec($pg, "begin work"));
  return(TRUE);
}

Function end_work($pg){
  pg_FreeResult(pg_Exec($pg, "end work"));
  return(TRUE);
}

Function abort_work($pg){
  pg_FreeResult(pg_Exec($pg, "abort"));
  return(TRUE);
}

where $pg is the database handle from pg_[p]connect().

--
Harry Waddell
Caravan Electronic Publishing