這是更新代碼Yii2更新中條件數組
$clients = OpClient::find(['id'])->where(['status'=>'Active'])->all();
foreach($clients as $client)
{
$array[] = $client['unit_id'];
$unit = OpUnit::find()->where(['id'=>$array]);
file_put_contents('test.txt',print_r($client['unit_id'],true));
$connection = Yii::$app->db;
$connection->createCommand()->update('op_unit', ['selected' => 'Yes'], 'id='.$array.'')->execute();
}
我應該如何在更新查詢其中ID是一個數組類型?它不斷顯示錯誤Array to string conversion
。任何建議都會得到讚揚。由於
我也試過。它顯示沒有錯誤,但數據庫沒有更新:/ – ron
通過'var_dump($ connection-> createCommand() - > update('user', ['selected'=>'Yes'],['' id'=> $ array]) - > createCommand() - > rawSql); die;' – Yupik
嘗試檢查真正的rawSql創建..答案更新與建議 – scaisEdge