我有一个简单的脚本,我希望在使用以下代码更新'Lookup'表(增加'nDeger'行)后更新表'Isler':
$PDOvt = new PDO ('mysql:dbname=' . VTAD . ';host=localhost', VTKA, VTP);
$PDOvt->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try
{
$Q2 = "SELECT @GRUPID:=nDeger as grupId FROM Lookup WHERE cAlan = 'nGrupId' FOR UPDATE;";
$Q3 = "UPDATE Lookup SET nDeger = nDeger + 1 WHERE cAlan = 'nGrupId';";
$Q4 = "UPDATE Isler SET nGrupId = @GRUPID
WHERE
konukID = :oturumKaydi
AND
kID = :kid
AND
nSiparisDurum = '-1'
AND
(durum = 4 OR durum = 5);";
$PDOvt->beginTransaction ();
$SMTP2 = $PDOvt->prepare ($Q2);
$SMTP3 = $PDOvt->prepare ($Q3);
$SMTP4 = $PDOvt->prepare ($Q4);
$SMTP4->bindValue (':oturumKaydi', $this->oturum_kaydi, PDO::PARAM_STR);
$SMTP4->bindValue (':kid', $this->kullanici_id, PDO::PARAM_INT);
$SMTP2->execute ();
$SMTP3->execute ();
$SMTP4->execute ();
$PDOvt->commit ();
$GRUPID = $SMTP2->fetchAll (PDO::FETCH_CLASS);
$_SESSION['iliskili_grup'] = $GRUPID[0]->grupId;
$this->iliskili_grup = $GRUPID[0]->grupId; // not incremented value
$PDOvt = null;
$this->debuggrupid = $vt->get_var("SELECT nDeger FROM Lookup WHERE cAlan = 'nGrupId' FOR UPDATE;"); // incremented value;
} catch (PDOException $e)
{
$PDOvt->rollBack ();
echo "HATA!";
}
我添加了一个带有不同连接的最后一个查询来检查nDeger的最后一个值,它看起来是增量的。
但似乎mysql在增加Lookup之前更新'Isler'。我试图改变两个更新的位置,但没有任何改变。