1 回答
TA贡献1789条经验 获得超10个赞
您需要单独运行每个查询。
此外,通常事务包含在 try catch 中。
try {
$pdo->beginTransaction();
$sql = 'INSERT INTO translation (lang, author, title, text)
VALUES(:lang, :author, :title, :text)';
$params = array("lang" => $lang,
"author" => $author,
"title" => $title,
"text" => $content,
);
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$sql = 'INSERT INTO article (translation, author, category, views, banner, visible)
VALUES(LAST_INSERT_ID(), :author, :category, 0, :banner, :visible)';
$params = array(
"author" => $author,
"category" => $category,
"banner" => $banner,
"visible" => $v
);
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$pdo->commit();
}catch (Exception $e){
$pdo->rollback();
throw $e;
}
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报