How to handle/catch error from database trigger, in YII2 -


this trigger

create or replace trigger trg_cek_pengurus before insert on tbl_pengurus each row declare     v_cek number(2); begin  if :new.jabatan = 1 or :new.jabatan = 2      select count(id)     v_cek     tbl_pengurus     idkoperasi = :new.idkoperasi , jabatan = :new.jabatan;      if v_cek > 0         raise_application_error (-20000, 'kepengurusan sudah ada');     end if;  end if; end; / 

nah.., if trigger have return value good,:v doesn't :v set raise_application_error

and controller

public function actiontambahpengurus() {     $model = new pengurus();      if ($model->load(yii::$app->request->post())){         $model->idkoperasi = yii::$app->user->identity->id;         if($model->save())             return $this->redirect('kepengurusan');      }      return $this->render('tambah-pengurus',[         'model' => $model,     ]); } 

and error

sqlstate[hy000]: general error: 20000 ocistmtexecute: ora-20000: kepengurusan sudah ada ora-06512: @ "db_koperasi.trg_cek_pengurus", line 13 ora-04088: error during execution of trigger 'db_koperasi.trg_cek_pengurus' (ext\pdo_oci\oci_statement.c:148) sql being executed was: insert "tbl_pengurus" ("nik", "nama", "jabatan", "email", "tgl_lahir", "alamat", "telepon", "idkoperasi") values ('2110131041', 'rahmat heru kurniawan', 1, 'rahmatheruka2@gmail.com2', '3 july, 2015', 'sidoarjo', '0987654321', 8) returning "id" :qp8 

this good, because tell me trigger working of course bad website. want handle this, i've tries various ways google, nothing works. please.. there can me?

as far remember, database related error throw yii\db\exception. can use standard try / catch block handle that:

try {     ... } catch (\yii\db\exception $e) {     ... } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -