Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Dec 26, 2019
1 parent 73b99b3 commit 65fa159
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/driver-mysqli/classes/LSYS/Database/MYSQLi.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function beginTransaction($mode = NULL)
throw new Exception ($connent->error, $connent->errno );
}
$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionBegin($connent));
$status = (bool) $connent->query('START TRANSACTION');
$status = (bool) @$connent->query('START TRANSACTION');
if (!$status) throw new Exception ($connent->error, $connent->errno );
$this->in_transaction=true;
return $status;
}
Expand All @@ -82,6 +83,7 @@ public function commit()

$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionCommit($connent));
$status = (bool) $connent->query('COMMIT');
if (!$status) throw new Exception ($connent->error, $connent->errno );
$this->in_transaction=false;
return $status;
}
Expand All @@ -95,6 +97,13 @@ public function rollback()
// Make sure the database is connected
$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionRollback($connent));
$status = (bool) $connent->query('ROLLBACK');
if (!$status){
if(in_array(intval($connent->errno), [2006,2013])&&strpos($connent->error, 'has gone away')!==false){
$this->in_transaction=false;
return true;
}
throw new Exception ($connent->error,$connent->errno);
}
$this->in_transaction=false;
return $status;
}
Expand Down
13 changes: 13 additions & 0 deletions src/driver-pdo-mysql/classes/LSYS/Database/PDO/MYSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
namespace LSYS\Database\PDO;
use LSYS\Database\Exception;

class MYSQL extends RWSPDO {
protected $identifier = '`';
public function getConnectManager()
{
if(!$this->connection) $this->connection= new \LSYS\Database\PDO\MYSQLRWSConnectManager($this->config);
return $this->connection;
}
public function rollback()
{
try {
return parent::rollback();
} catch (Exception $e) {
if(in_array(intval($e->getCode()), [2006,2013])&&strpos($e->getMessage(), 'has gone away')!==false){
return true;
}
throw $e;
}
}
}
12 changes: 9 additions & 3 deletions src/driver-pdo/classes/LSYS/Database/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function beginTransaction($mode = NULL)
{
$connent=$this->getConnectManager()->getConnect(ConnectManager::CONNECT_MASTER_MUST);
$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionBegin($connent));
return $connent->beginTransaction();
$status=$connent->beginTransaction();
if (!$status)throw new Exception ($connent->errorInfo(),$connent->errorCode());
return $status;
}
/**
* {@inheritDoc}
Expand All @@ -45,7 +47,9 @@ public function commit()
{
$connent=$this->getConnectManager()->getConnect(ConnectManager::CONNECT_MASTER_MUST);
$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionCommit($connent));
return $connent->commit();
$status=@$connent->commit();
if (!$status)throw new Exception ($connent->errorInfo(),$connent->errorCode());
return $status;
}
/**
* {@inheritDoc}
Expand All @@ -55,7 +59,9 @@ public function rollback()
{
$connent=$this->getConnectManager()->getConnect(ConnectManager::CONNECT_MASTER_MUST);
$this->event_manager&&$this->event_manager->dispatch(DBEvent::transactionRollback($connent));
return $connent->rollBack();
$status=$connent->rollBack();
if (!$status)throw new Exception ($connent->errorInfo(),$connent->errorCode());
return $status;
}
public function quote($value,$value_type=null) {
if(is_string($value)||is_numeric($value)){
Expand Down

0 comments on commit 65fa159

Please sign in to comment.