含有事务应用的删除操作
path:E:\Xampp\htdocs\yii2\sport_equipment\common\models\Equipment.php
public function delete()
{
if (!$this->isTransactional(self::OP_DELETE)) {
return $this->deleteInternal();
}
$db = Yii::$app->db;
$transaction = $db->beginTransaction();
try {
$db->createCommand(‘UPDATE post SET status=1 WHERE id=1’)->execute();
$result = $this->deleteInternal();
if ($result === false) {
$transaction->rollBack();
} else {
$transaction->commit();
}
} catch(\Exception $e) {
$transaction->rollBack();
throw $e;
} catch(\Throwable $e) {
$transaction->rollBack();
throw $e;
}
}
mySql获取当前时间
1 | SELECT current_date(), curdate(), curdate() + 0; # '2018-03-09' '2018-03-09' 20180309 |
数据库插入时报错
The SQL being executed was: INSERT INTO equipment
(eqpid
, catid
) VALUES (‘c2002’, ‘c2’)
1 | Error Info: Array |
Caused by: PDOException
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn’t match value count at row 1