|
Posted by NC on 10/14/31 11:50
tuco357@gmail.com wrote:
>
> This problem has been vexing me for some time and I thought
> I should consult the group....
I think reading the MySQL manual coould be even more helpful.
> Often times when writing a php script to handle some mysql DB
> transactions, I must write code that performs, say, an insert into a
> MySQL DB, then retrieves the last item's index, and makes a new
> insertion into another table on the DB that requires the previously
> obtained index. Both queries must be executed and completed -
> if query one succeeds and query two fails, I roll back the changes
> of query one.
So you should use transactions...
> Suppose that in the original example, query one is executed and
> completed. However, just before query two is made by the PHP
> script, the whole darn server goes down. Thus, query one is
> complete, query two never took place, and when the server is
> restarted, the database is corrupt!
If you use transactions, this is not going to happen, since nothing
will be commited until the second query is successfully executed.
> Obviously, my solution is the pits. What would you do?
Learn about transactions:
http://dev.mysql.com/doc/refman/4.1/en/commit.html
Cheers,
NC
Navigation:
[Reply to this message]
|