Transactions in multiple PHP pages using MYSQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SzCs
Forum Newbie
Posts: 4
Joined: Fri Feb 28, 2003 3:56 am

Transactions in multiple PHP pages using MYSQL

Post by SzCs »

Hallo!

I'd like to get some information. I've got 2 problem:

-If several user edit the same row simultaneously, only the last result will remain in the db. How can I avoid that? I tried to write the sessionid of the first editor in the row, and block the other users to edit the same row. Any other/better idea?

-I've got some DML (insert,update,delete) step in several php, and I'd like to handle them as a transaction. If I good know, it cannot done with standard mysql commands, because every db access stop at the end of a php. How can I do that?

Thx.

SzCs
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

Could you possibly make a login, and if any of the users are listed as being logged in, just not let other users have access to the page where they update? I dunno, if they're connecting from other places that wouldn't work.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Re: Transactions in multiple PHP pages using MYSQL

Post by BDKR »

SzCs wrote:Hallo!

I'd like to get some information. I've got 2 problem:

-If several user edit the same row simultaneously, only the last result will remain in the db. How can I avoid that? I tried to write the sessionid of the first editor in the row, and block the other users to edit the same row. Any other/better idea?

-I've got some DML (insert,update,delete) step in several php, and I'd like to handle them as a transaction. If I good know, it cannot done with standard mysql commands, because every db access stop at the end of a php. How can I do that?

Thx.

SzCs
Hi,

Well, first off, you don't want several users to have simultaneous access to a row! This kind of thing can result in data corruption. What is your application doing that you would desire this?

As for transactions, are you talking about transactions from a database point of view? If that be the case, and you're using MySQL, you will also need to use the Inno base tables and start all transactions with a BEGIN command to the db. If everything works as planned, write the information to disk with a COMMIT command. Otherwise, you can back out of all of your changes with a ROLLBACK command.

Now I'm not really sure what it is you're doing and/or talking about so I apologize if none of this helps.

Cheers,
BDKR
SzCs
Forum Newbie
Posts: 4
Joined: Fri Feb 28, 2003 3:56 am

Post by SzCs »

Thats it. I don't want several users to have simultaneous access to a row! I'd like to know, how can I avoid it.

And the transactions are transactions from a database point of view. But I can't use BEGIN, COMMIT and ROLLBACK, because the duration of a transaction can't be longer than a single php. My application uses around 10 php for a single "transaction". (get the name of a project, choose the place of the project from a hierarchical /javascript/ tree, choose the manager from an other tree....) So I can't use BEGIN, COMMIT and ROLLBACK, so I need some other solution.

Thx.

SzCs
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

What exactly are you trying to do? I understand you don't want people accessing the same row at the same time, so maybe you could set up permissions to the database. And I have no clue what you're talking about the the single lines of php code. Maybe if you explain exactly what you're trying to accomplish with the database we could be of more help.

Jade
Post Reply