Reply to Re: Damage Control: When 1 of 2+ Interdependent mySQL Queries Fail...

Your name:

Reply:


Posted by NC on 10/10/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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация