zoukankan      html  css  js  c++  java
  • PHP Mysql Innodb 事务操作

    <?php
    //要么全部执行,要么全部不执行;
            // put your code here
            $conn = mysql_connect('localhost','root','') or die ("数据连接错误!!!");
            mysql_select_db('test',$conn);
            mysql_query("set names 'GBK'"); //使用GBK中文编码;
            //开始一个事务
            mysql_query("BEGIN"); //或者mysql_query("START TRANSACTION");
            $sql = array();
            $sql[] = "INSERT INTO `jos_innotest` (`id`, `username`, `sex`) VALUES (NULL, 'user1', '10');";
            $sql[] = "INSERT INTO `jos_innotest` (`id`, `username`, `sex`) VALUES (NULL, 'user2', '20');";//这条我故意写错
            $sql[] = "INSERT INTO `jos_innotest` (`id`, `username`, `sex`) VALUES (NULL, 'user3', '30');";
            $sql[] = "INSERT INTO `jos_innotest` (`id`, `username`, `sex`) VALUES (NULL, 'user4', '40');";
    
            $r = 1;
            foreach($sql as $key => $row) {
                $res = mysql_query($row);
                if(!$res) {$r = 0;}
            }
            if(!$r) {mysql_query("ROLLBACK");}else {mysql_query("COMMIT");}
    
            mysql_query("END");
    ?>
    
  • 相关阅读:
    a.default.ERROR.httpAjax is not a function
    Java heap space
    jmeter
    sql注入
    数据库查前三名
    maven
    国际化变现应用分析
    百度应用部署秘籍
    如何建立起一套有效的APP监控体系
    第三方舆情收集与质量闭环建设
  • 原文地址:https://www.cnblogs.com/17too/p/2293023.html
Copyright © 2011-2022 走看看