最好的辦法是模仿嵌套事務。 (pseduocode)
class MyMysqli {
protected $realDb;
protected $transaction_count =0;
public function __construct ($host, $username , $passwd, $dbname){
$this->realDb = new Mysqli($host, $username, $passwd, $dbname);
}
public function __get($property){
return $this->realDb->$property;
}
public function __set($property, $value){
return $this->realDb->$property = $value;
}
public function __call($method, $args){
return call_user_func_array(array($this->realDb, $method), $args);
}
// overload begin_transaction, commit and rollback
public function begin_transaction(){
$this->transaction_count++;
if ($this->transaction_count == 1){
$this->realDb->begin_transaction();
}
}
public function commit(){
$this->transaction_count--;
if($this->transaction_count == 0){
$this->realDb->commit();
}
}
public function rollback(){
throw new Exception("Error");
}
你將需要更清楚地解釋一下。這是什麼樣的交易? –
這是一個MySQL事務。像http://stackoverflow.com/questions/2708237/php-mysql-transactions-examples – Jordy
@jordy以及停止:)你真的應該採用新的數據庫引擎之一...不推薦使用mysql擴展。 – Orangepill