0

I'm developing an application that will use a server to sync data, this server will use php and a mysql database.

To the sync process I'm thinking is a 3 way communication:

1 - The client sends the data to the server, the server handle the data and reply to the client with an OK or ERROR, at this point the server should begin the transaction. 2 - The client if receive OK just updates the internal info (update date and delete some rows from the database) 3 - The client sends another request to the server (OK or CANCEL), when the server receives this new request it commits or rollback the transaction.

Is this possible? Start the transaction in one request and commit the transaction in another? In case of YES, how? Sessions?

Or should i do this in another way?

MckPT
  • 33
  • 2
  • 7

1 Answers1

0

in php you shouldnt store objects in the session(citation needed). so what i would do is store the data into session, and when you receive the confirmation from the client retrieve the data and assemble the query(mysqli or PDO, the one you like).

this will work unless you need to use some data from the database(IE last_inser_id) if thats the case i dont kwnow how to do that, and im tempted to say thats impossible (dont remember, but i think that php closes the DB session when the script ends)

Jarry
  • 1,891
  • 3
  • 15
  • 27
  • in the case of needing additional data from the previous database request(like the insert id), in the case of PDO or MySQLi; you could do `$pdoObject->lastInsertId();` or `$mysqliObject->insert_id` – Emmanuel Okeke Jun 06 '12 at 14:54
  • there are two different requests, `lastInsertId` or `insert_id` would not return the id inserted on another session. you can use persitent connections providing you disable the automatic cleanup, but i wouldnt recommend that.(http://php.net/manual/en/mysqli.persistconns.php) – Jarry Jun 06 '12 at 15:12