where (['seriesId'=>1600])->orderBy('ID');$cardNum=2;foreach(">
我正在嘗試進行一個遷移,它會同時在不同的表上執行多個查詢
$sql = ''; $sql .= "UPDATE card_series SET Code = 903 WHERE ID = 1600;"; $cardsSeries1600 = CardList::find() ->where(['seriesId' => 1600]) ->orderBy('ID'); $cardNum = 2; foreach ($cardsSeries1600->each() as $card) { if ($card->client_id != NULL) { $sql .= "DELETE FROM client_cards WHERE card_id = ".$card->ID.";"; } $number = str_pad($cardNum, 8, "0", STR_PAD_LEFT); $cardId = (1903).$number; $sql .= "UPDATE card_list SET ID = '".$cardId."', Code = 903, Number = '".$number."' WHERE ID = ".$card->ID.";"; $sql .= "UPDATE card_list_log SET card_id = '".$cardId."', Code = 903, Number = '".$number."' WHERE card_id = ".$card->ID.";"; $cardNum++; } \Yii::$app->db->createCommand($sql)->execute();
但最後,我只有一個第一個請求UPDATE card_series SET Code = 903 WHERE ID = 1600;
#我嘗試列印$sql
變量,所有的請求都在那裡,但只有第一個請求被執行
我該如何做才能讓所有的請求一個接一個地執行?
你可以嘗試以下方式。