Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Base\Database\Adapter;
- use Phalcon\Db\Adapter\Pdo;
- class MasterSlaveAdapter extends Pdo
- {
- /**
- * @var Pdo
- */
- protected $masterConnection;
- /**
- * @var Pdo
- */
- protected $slaveConnection;
- /**
- * @param Pdo $masterConnection
- * @param Pdo $slaveConnection
- */
- public function __construct(
- Pdo $masterConnection,
- Pdo $slaveConnection
- ) {
- $this->masterConnection = $masterConnection;
- $this->slaveConnection = $slaveConnection;
- }
- /**
- * @return Pdo
- */
- public function getMasterConnection()
- {
- return $this->masterConnection;
- }
- /**
- * @return Pdo
- */
- public function getSlaveConnection()
- {
- return $this->slaveConnection;
- }
- /**
- * @param array|null $descriptor
- * @return bool
- */
- public function connect($descriptor = null)
- {
- $this->getMasterConnection()->connect($descriptor);
- $this->getSlaveConnection()->connect($descriptor);
- return true;
- }
- /**
- * @param string $sqlStatement
- * @return ?
- */
- public function prepare($sqlStatement)
- {
- return $this->getMasterConnection()->prepare($sqlStatement);
- }
- /**
- * @param \PDOStatement $statement [description]
- * @param array $placeholders [description]
- * @param [type] $dataTypes [description]
- * @return [type] [description]
- */
- public function executePrepared(\PDOStatement $statement, array $placeholders, $dataTypes)
- {
- return $this->getMasterConnection()->executePrepared(
- $statement,
- $placeholders,
- $dataTypes
- );
- }
- /**
- * @param string $sqlStatement
- * @param array $bindParams
- * @param array $bindTypes
- * @return bool
- */
- public function execute($sqlStatement, $bindParams = null, $bindTypes = null)
- {
- return $this->getMasterConnection()->execute(
- $sqlStatement,
- $bindParams,
- $bindTypes
- );
- }
- /**
- * @param string $sqlStatement
- * @param array $bindParams
- * @param array $bindTypes
- * @return bool
- */
- public function query($sqlStatement, $bindParams = null, $bindTypes = null)
- {
- return $this->getSlaveConnection()->query(
- $sqlStatement,
- $bindParams,
- $bindTypes
- );
- }
- /**
- * @return int
- */
- public function affectedRows()
- {
- return $this->getMasterConnection()->affectedRows();
- }
- /**
- * @return bool
- */
- public function close()
- {
- $this->getMasterConnection()->close();
- $this->getSlaveConnection()->close();
- return true;
- }
- /**
- * @param string $string
- * @return string
- */
- public function escapeString($string)
- {
- return $this->getMasterConnection()->escapeString($string);
- }
- /**
- * @param string $sequenceName
- * @return int | bool
- */
- public function lastInsertId($sequenceName = null)
- {
- return $this->getMasterConnection()->lastInsertId($sequenceName);
- }
- /**
- * @param bool $nesting
- * @return bool
- */
- public function begin($nesting = true)
- {
- return $this->getMasterConnection()->begin($nesting);
- }
- /**
- * @param bool $nesting
- * @return bool
- */
- public function rollback($nesting = true)
- {
- return $this->getMasterConnection()->rollback($nesting);
- }
- /**
- * @param bool $nesting
- * @return bool
- */
- public function commit($nesting = true)
- {
- return $this->getMasterConnection()->commit($nesting);
- }
- /**
- * @return int
- */
- public function getTransactionLevel()
- {
- return $this->getMasterConnection()->getTransactionLevel();
- }
- /**
- * @return boolean
- */
- public function isUnderTransaction()
- {
- return $this->getMasterConnection()->isUnderTransaction();
- }
- /**
- * @return \Pdo
- */
- public function getInternalHandler()
- {
- return $this->getMasterConnection()->getInternalHandler();
- }
- /**
- * @return array
- */
- public function getErrorInfo()
- {
- return [
- 'master' => $this->getMasterConnection()->getErrorInfo(),
- 'slave' => $this->getSlaveConnection()->getErrorInfo()
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement