Transactions in Postgres

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

Transactions in Postgres

От:
root <trevor@hailix.com>
Дата:
HI,

I am running Postgresql-7.2 with PHP 4.1.1 and I am beginning to use
transactions inside of a php script:

$Link = pg_connect("host=$Host dbname=$DBName user=$User") or die
("Couldn't connect to the database $DBName");

 $Query = "BEGIN WORK; INSERT into $TableName
(firstname,lastname,emailaddress,comments,created)
values('$Array[FirstName]',
'$Array[LastName]','$Array[email]','$Array[Comments]', 'now()');
COMMIT;";

 // Test to see if the query was succeful or not

 pg_exec($Link, $Query) or die ("Couldn't insert name $firstname");

 if (pg_exec($Link,$Query)) {
 echo "

Insert was successful

"; } else { echo "

Insert was not successful

"; What I am finding is that this query will insert a new name twice in the database within milliseconds of each other. What am I missing in doing this? Any help is appreciated. Trevor

Re: Transactions in Postgres

От:
Ivan Horvath <pillesoft@yahoo.co.uk>
Дата:
hi

you do exactly twice the execution of the sql command
(pg_exec)


--- root  wrote:
> HI,
> 
> I am running Postgresql-7.2 with PHP 4.1.1 and I am
> beginning to use
> transactions inside of a php script:
> 
> $Link = pg_connect("host=$Host dbname=$DBName
> user=$User") or die
> ("Couldn't connect to the database $DBName");
> 
>  $Query = "BEGIN WORK; INSERT into $TableName
> (firstname,lastname,emailaddress,comments,created)
> values('$Array[FirstName]',
>
'$Array[LastName]','$Array[email]','$Array[Comments]',
> 'now()');
> COMMIT;";
> 
>  // Test to see if the query was succeful or not
> 
>  pg_exec($Link, $Query) or die ("Couldn't insert
> name $firstname");
> 
>  if (pg_exec($Link,$Query)) {
>  echo "

Insert was successful

"; > } else { > echo "

Insert was not successful

"; > > What I am finding is that this query will insert a > new name twice in the > database within milliseconds of each other. What am > I missing in doing > this? Any help is appreciated. > > Trevor > > > ---------------------------(end of > broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please > send an appropriate > subscribe-nomail command to majordomo@postgresql.org > so that your > message can get through to the mailing list cleanly ===== Best Regards, Ivan Horvath Anyone who has never made a mistake has never tried anything new. /Albert Einstein/ __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/

Re: Transactions in Postgres

От:
"Josh Berkus" <josh@agliodbs.com>
Дата:
Trevor,

> I am running Postgresql-7.2 with PHP 4.1.1 and I am beginning to use
> transactions inside of a php script:

This issue has been raised and resolved on the pgsql-php list.  Browse
 the archives of that list, and if you can't find it, post your
 question to pgsql-php.

FWIW, transactions within postgres must happen in a single connection.

-Josh Berkus

Re: Transactions in Postgres

От:
Ugly Hippo <ugly_hippo@yahoo.ca>
Дата:
You are running pg_exec twice, so you should get two
inserts.

Try:

$result = pg_exec(....
if($result)...

HTH,
Troy

--- root  wrote:
> HI,
> 
> I am running Postgresql-7.2 with PHP 4.1.1 and I am
> beginning to use
> transactions inside of a php script:
> 
> $Link = pg_connect("host=$Host dbname=$DBName
> user=$User") or die
> ("Couldn't connect to the database $DBName");
> 
>  $Query = "BEGIN WORK; INSERT into $TableName
> (firstname,lastname,emailaddress,comments,created)
> values('$Array[FirstName]',
>
'$Array[LastName]','$Array[email]','$Array[Comments]',
> 'now()');
> COMMIT;";
> 
>  // Test to see if the query was succeful or not
> 
>  pg_exec($Link, $Query) or die ("Couldn't insert
> name $firstname");
> 
>  if (pg_exec($Link,$Query)) {
>  echo "

Insert was successful

"; > } else { > echo "

Insert was not successful

"; > > What I am finding is that this query will insert a > new name twice in the > database within milliseconds of each other. What am > I missing in doing > this? Any help is appreciated. > > Trevor > > > ---------------------------(end of > broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please > send an appropriate > subscribe-nomail command to majordomo@postgresql.org > so that your > message can get through to the mailing list cleanly ______________________________________________________________________ Music, Movies, Sports, Games! http://entertainment.yahoo.ca
FAQ