• 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");
    ?>
    
  • 相关阅读:
    JavaScript
    CSS
    HTML5&CSS
    I2C mux和复杂拓扑
    如何实例化I2C设备
    SMBus 协议
    I2C 协议
    I2C和SMBus简介
    ubuntu20.04系统下更新Raspberry Pi4的DTB
    通过configfs配置的Linux USB gadget
  • 原文地址:https://www.cnblogs.com/17too/p/2293023.html
Copyright © 2020-2023  润新知