English 中文(简体)
停电两条最新情况
原标题:Locking row for two updates

我需要对浏览量做两处更新,但我需要确保这些更新能够一起进行,而且从另一个用户那里没有任何其他查询可以干扰。 我知道<条码>。 通用名称,但我想在第一次更新之后,这当然会锁定,这意味着有人会干扰第二次更新。 如果其他人首先更新这一行文,更新工作就会奏效,但将会更新数据。 是否有办法确保这两个最新情况如何? 我被告知交易情况,但只要我知道,这些交易对确保实际发生两次更新,而不是“再次”进行,除非我错了,而且各行将锁在交易之前?

这里的问题是:

www.un.org/spanish/ga UPDATE table SET x=x+2 WHERE x>z

www.un.org/spanish/ga WHERE y>z

I made a mistake and didn t give full information. That was my fault. I have updated the queries. The issue I have is that z can be updated as well. If z is updated after the SELECT but before the other two updates, the data can get messed up. Does doing the transaction BEGIN/COMMIT work for that?

最佳回答

Learn about TRANSACTION http://dev.mysql.com/doc/refman/5.0/en/commit.html

[... connect ...]

mysql_query("BEGIN");

$query1 = mysql_query( UPDATE table SET x=x+2 WHERE x>y );
$query2 = mysql_query( UPDATE table SET y=y+2 WHERE y>y );

if($query1 && $query2) {
    mysql_query("COMMIT");  
    echo  Save Done. All UPDATES done. ;  
} else {
    mysql_query("ROLLBACK");  
    echo  Error Save. All UPDATES reverted, and not done. ;  
}
问题回答

交易量各异,但基本上按“ACID,您应期望,在某项交易中,所有读写和增订内容均符合consently>,意思是将其保留在有效状态中,但更重要的是,一项交易是>><>>>>><>>>/strong>,在另一项交易(已经做)中,不会干扰你的交易(选择和增补小组); 页: 1

每个数据库可以不同地处理tic学(有些可能会锁定行或栏目,有些可能重新排序,有些可能序列化),但可以自动处理申报数据库接口:你担心你想要完成的工作。

如所述,MySQL InnoDB是交易,将支持上述内容,以确保与InnoDB合作安排你的表格,其他非交易发动机(如MyISAM)不是交易,因此将迫使你人工管理这些交易杂质(锁)。

一种做法是将整个表格锁定下来:

LOCK TABLE `table` WRITE;
SELECT z FROM `table` WHERE id= $id ;
UPDATE `table` SET x=x+2 WHERE x>z;
UPDATE `table` SET y=y+2 WHERE y>z;
UNLOCK TABLES;

这将防止其他会议在选任考试和评审期间从<条码>>表表中进行写作和阅读。

这是否是一个适当的解决办法,取决于会议何时读或写。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...