0%

数据库大作业笔记(九)

mysql抛出异常:

1
2
3
4
5
IF(!(new.eqpid LIKE CONCAT(new.catid,'%'))) 
THEN SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = '输入错误' ;
-- set new.eqpid=NULL;
ELSE insert into audit_equipment VALUES(new.eqpid,user(),now(),1);
END IF;

php:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
try{
$model = new Equipment();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->eqpid]);
}
}catch(\Exception $e){

}
return $this->render('create', [
'model' => $model,
]);
}