【PHP】mysql嵌套事物

Continue Read..

公司的一个项目需要在一个函数里面的调用多个函数,但是每个函数都用到了mysql事物,按照原生的mysql事物,只有一层

也就是说 A函数包含了B函数,如果B函数事物成功,A再没有commit的时候也能提交事物,这样就不对了

 

直接上代码

 

写一个class

定义一个静态变量

//事物laravel

static private $transactions = 0;

 

public function begin() {
        ++self::$transactions;
        if (self::$transactions == 1) {
            $sql = 'BEGIN';
            $conn = $this->getMasterConn();
            
            return DBMysqli::execute($conn, $sql);
        }
	}

	/**
	 * 提交事务
	 *
	 * @return bool
	 * @throws Exception
	 */
	public function commit() {
        if (self::$transactions == 1) {
            $sql = 'COMMIT';
            $conn = $this->getMasterConn();
            
            return DBMysqli::execute($conn, $sql);
        }
        --self::$transactions;
	}

	/**
	 * 回滚事务
	 *
	 * @return bool
	 * @throws Exception
	 */
	public function rollback() {
        if (self::$transactions == 1) {
            self::$transactions = 0;
            $sql = 'ROLLBACK';
            $conn = $this->getMasterConn();
    
            return DBMysqli::execute($conn, $sql);
        } else {
            --self::$transactions;
        }
	}

参考网站 https://blog.csdn.net/hello_katty/article/details/45220825

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【js】数字转汉字

Continue Read..
function DX(n) {
    if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
        return "数据非法";
    var unit = "千百拾亿千百拾万千百拾元角分", str = "";
    n += "00";
    var p = n.indexOf('.');
    if (p >= 0)
        n = n.substring(0, p) + n.substr(p+1, 2);
    unit = unit.substr(unit.length - n.length);
    for (var i=0; i < n.length; i++)
        str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
    return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
}

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权