Skip to content

Commit

Permalink
Finish 0.2.0
Browse files Browse the repository at this point in the history
News:
  ReconnectingPDOStatement is given everywhere instead PDOStatement
Minor changes
  License fix
  Namespace fix
  Continous integration
  • Loading branch information
adamturcsan committed Nov 15, 2016
2 parents b5dd446 + e5c040e commit 879c599
Show file tree
Hide file tree
Showing 16 changed files with 906 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/tmp/
/test/configuration.xml
/test/configuration.xml
/phpunit-xdebug
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
language: php

php:
- '5.5'
- 5.6

before_install:
- composer self-update
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[![Build Status](https://travis-ci.org/adamturcsan/reconnecting-pdo.svg?branch=master)](https://travis-ci.org/adamturcsan/reconnecting-pdo)
[![Coverage Status](https://coveralls.io/repos/github/adamturcsan/reconnecting-pdo/badge.svg?branch=feature%2Freconnecting-statement)](https://coveralls.io/github/adamturcsan/reconnecting-pdo?branch=feature%2Freconnecting-statement)
# reconnecting-pdo
PDO object which can reconnect if server has gone away
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"autoload": {
"psr-4": {
"Legow\\ReconnectingPDO\\": "src/"
"LegoW\\ReconnectingPDO\\": "src/"
}
},
"require-dev": {
Expand Down
9 changes: 5 additions & 4 deletions src/ConnectionParametersMissingException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/*
* All rights reserved © 2016 Legow Hosting Kft.
* LegoW\ReconnectingPDO (https://github.com/adamturcsan/reconnecting-pdo)
*
* @copyright Copyright (c) 2014-2016 Legow Hosting Kft. (http://www.legow.hu)
* @license https://opensource.org/licenses/MIT MIT License
*/

declare (strict_types = 1);

namespace Legow\ReconnectingPDO;
namespace LegoW\ReconnectingPDO;

/**
* Description of ConnectionParametersMissingException
Expand Down
20 changes: 20 additions & 0 deletions src/CursorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* LegoW\ReconnectingPDO (https://github.com/adamturcsan/reconnecting-pdo)
*
* @copyright Copyright (c) 2014-2016 Legow Hosting Kft. (http://www.legow.hu)
* @license https://opensource.org/licenses/MIT MIT License
*/

namespace LegoW\ReconnectingPDO;

/**
* Description of CursorException
*
* @author Turcsán Ádám <turcsan.adam@legow.hu>
*/
class CursorException extends \Exception
{
//put your code here
}
9 changes: 5 additions & 4 deletions src/ExceededMaxReconnectionException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/*
* All rights reserved © 2016 Legow Hosting Kft.
* LegoW\ReconnectingPDO (https://github.com/adamturcsan/reconnecting-pdo)
*
* @copyright Copyright (c) 2014-2016 Legow Hosting Kft. (http://www.legow.hu)
* @license https://opensource.org/licenses/MIT MIT License
*/

declare (strict_types = 1);

namespace Legow\ReconnectingPDO;
namespace LegoW\ReconnectingPDO;

/**
* Description of ExceededMaxReconnectionException
Expand Down
24 changes: 17 additions & 7 deletions src/ReconnectingPDO.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

namespace Legow\ReconnectingPDO;
/*
* LegoW\ReconnectingPDO (https://github.com/adamturcsan/reconnecting-pdo)
*
* @copyright Copyright (c) 2014-2016 Legow Hosting Kft. (http://www.legow.hu)
* @license https://opensource.org/licenses/MIT MIT License
*/

namespace LegoW\ReconnectingPDO;

use PDO;
use LegoW\ReconnectingPDO\ReconnectingPDOStatement;

/**
* It covers the PDO database handler to prevent connection loss caused by non-critical
Expand All @@ -12,7 +20,7 @@
*
* @author Turcsán Ádám <turcsan.adam@legow.hu>
* @method PDOStatement|bool prepare(string $statement, array $driver_options = 'array()' [optional]) Prepares a statement for execution and returns a statement object
* @method bool beginTransaction(type $paramName) Initiates a transaction
* @method bool beginTransaction() Initiates a transaction
* @method bool commit() Commits a transaction
* @method bool rollBack() Rolls back a transaction
* @method bool inTransaction() Checks if inside a transaction
Expand Down Expand Up @@ -106,7 +114,7 @@ protected function call($method, $arguments)
throw new ReconnectingPDOException('No PDO connection is set');
}
try {
return call_user_func_array([$this->db, $method], $arguments);
$returnValue = call_user_func_array([$this->db, $method], $arguments);
} catch (\PDOException $ex) {
if (!stristr($ex->getMessage(), "server has gone away") || $ex->getCode() != 'HY000') {
throw $ex;
Expand All @@ -115,12 +123,15 @@ protected function call($method, $arguments)
$this->reconnectDb();
$returnValue = $this->call($method, $arguments); // Retry
$this->resetCounter();
return $returnValue;
} else {
throw new ExceededMaxReconnectionException('ReconnectingPDO has exceeded max reconnection limit',
$ex->getCode(), $ex);
}
}
if ($returnValue instanceof \PDOStatement) {
return new ReconnectingPDOStatement($returnValue, $this, $method === 'query');
}
return $returnValue;
}

protected function reconnectDb()
Expand Down Expand Up @@ -153,7 +164,7 @@ public function setMaxReconnection($max)
{
$this->maxReconnection = $max;
}

/**
*
* Parameters can be <b>(string)dsn</b>, <b>(string)username</b>,
Expand All @@ -169,7 +180,7 @@ public function setConnectionParameters($parameters, $autoconnect = false)
$this->$key = $param;
}
}
if($autoconnect) {
if ($autoconnect) {
$this->connectDb();
}
}
Expand All @@ -189,5 +200,4 @@ protected function connectionParametersAreSet()
}
return false;
}

}
9 changes: 5 additions & 4 deletions src/ReconnectingPDOException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/*
* All rights reserved © 2016 Legow Hosting Kft.
* LegoW\ReconnectingPDO (https://github.com/adamturcsan/reconnecting-pdo)
*
* @copyright Copyright (c) 2014-2016 Legow Hosting Kft. (http://www.legow.hu)
* @license https://opensource.org/licenses/MIT MIT License
*/

declare (strict_types = 1);

namespace Legow\ReconnectingPDO;
namespace LegoW\ReconnectingPDO;

/**
* Description of ReconnectingPDOException
Expand Down
Loading

0 comments on commit 879c599

Please sign in to comment.