/** * @param array|null $parameters * @param bool|null $disableQueryBuffering * @throws CM_Db_Exception * @return CM_Db_Result */ public function execute(array $parameters = null, $disableQueryBuffering = null) { $disableQueryBuffering = (bool) $disableQueryBuffering; $retryCount = 1; for ($try = 0; true; $try++) { try { if ($disableQueryBuffering) { $this->_client->setBuffered(false); } @$this->_pdoStatement->execute($parameters); if ($disableQueryBuffering) { $this->_client->setBuffered(true); } CM_Service_Manager::getInstance()->getDebug()->incStats('mysql', $this->getQueryString()); return new CM_Db_Result($this->_pdoStatement); } catch (PDOException $e) { if ($try < $retryCount && $this->_client->isConnectionLossError($e)) { $this->_client->disconnect(); $this->_client->connect(); $this->_reCreatePdoStatement(); continue; } throw new CM_Db_Exception('Cannot execute SQL statement', null, ['tries' => $try, 'originalExceptionMessage' => $e->getMessage(), 'query' => $this->_pdoStatement->queryString]); } } throw new CM_Db_Exception('Line should never be reached'); }
public function testReconnectTimeout() { $config = CM_Service_Manager::getInstance()->getDatabases()->getMaster()->getConfig(); $config['reconnectTimeout'] = 5; $client = new CM_Db_Client($config); $client->connect(); $firstTime = $client->getLastConnect(); $timeForward = 100; CMTest_TH::timeForward($timeForward); $client->createStatement('SELECT 1')->execute(); $this->assertSameTime($firstTime + $timeForward, $client->getLastConnect(), 5); CMTest_TH::timeForward($timeForward); $client->createStatement('SELECT 1')->execute(); $this->assertSameTime($firstTime + 2 * $timeForward, $client->getLastConnect(), 5); }