Home  >  Article  >  Backend Development  >  请教pdo的事务处理中可以使用预处理么

请教pdo的事务处理中可以使用预处理么

WBOY
WBOYOriginal
2016-06-13 13:07:411058browse

请问pdo的事务处理中可以使用预处理么?
请问pdo的事务处理中可以使用预处理么?例如下面的代码异常后,可以回滚事务么?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
try{
    $pdo->beginTransaction();
    $sql = 'INSERT ...';
    $pdo_pre = $pdo->prepare($sql);
    $pdo_pre->execute();
}catch(PDOException $e){
    $pdo->->rollBack();
}


PDO的事务操作仅对PDO方法生效,还是PDO和PDOStatement都生效呢?
谢谢!

------解决方案--------------------
都生效的
但是我在你的代码里面没有看到commit
------解决方案--------------------
看下mysql的事务
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn