logger = new NullLogger(); $this->connectionUri = $connUri; $this->preOptions = $preOptions; $this->postOptions = $postOptions; $this->validateConnUri(); $this->reconnect(); } public function reconnect($force = false) { if ($this->isConnected() && !$force) { return false; } // Release old instance $this->disconnect(); // Connect $this->createPdoInstance(); return true; } public function disconnect() { $this->stmtCache = []; $this->instance = null; } protected function createPdoInstance() { $pdoConnectionString = $this->createPdoConnStr($this->connectionUri); // Create Connection $this->instance = new PDO( $pdoConnectionString, $this->connectionUri->getUsername(), $this->connectionUri->getPassword(), (array)$this->preOptions ); $this->connectionUri = $this->connectionUri->withScheme($this->getInstance()->getAttribute(PDO::ATTR_DRIVER_NAME)); $this->setPdoDefaultParams($this->postOptions); } /** * @throws NotAvailableException */ protected function validateConnUri() { if (!defined('PDO::ATTR_DRIVER_NAME')) { throw new NotAvailableException("Extension 'PDO' is not loaded"); } $scheme = $this->connectionUri->getScheme(); if ($this->connectionUri->getScheme() != "pdo" && !extension_loaded('pdo_' . strtolower($scheme))) { throw new NotAvailableException("Extension 'pdo_" . strtolower($this->connectionUri->getScheme()) . "' is not loaded"); } if ($this->connectionUri->getQueryPart(self::STATEMENT_CACHE) == "true") { $this->useStmtCache = true; } } protected function setPdoDefaultParams($postOptions = []) { // Set Specific Attributes $defaultPostOptions = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_STRINGIFY_FETCHES => false, ]; $defaultPostOptions = $defaultPostOptions + (array)$postOptions; foreach ((array) $defaultPostOptions as $key => $value) { $this->getInstance()->setAttribute($key, $value); } } protected function createPdoConnStr(Uri $connUri) { if ($connUri->getScheme() == "pdo") { return $this->preparePdoConnectionStr($connUri->getHost(), ".", null, null, $connUri->getQuery()); } else { return $this->preparePdoConnectionStr($connUri->getScheme(), $connUri->getHost(), $connUri->getPath(), $connUri->getPort(), $connUri->getQuery()); } } public function preparePdoConnectionStr($scheme, $host, $database, $port, $query) { if (empty($host)) { return $scheme . ":" . $database; } $database = ltrim(empty($database) ? "" : $database, '/'); if (!empty($database)) { $database = ";dbname=$database"; } $pdoConnectionStr = $scheme . ":" . ($host != "." ? "host=" . $host : "") . $database; if (!empty($port)) { $pdoConnectionStr .= ";port=" . $port; } parse_str($query, $queryArr); unset($queryArr[self::DONT_PARSE_PARAM]); unset($queryArr[self::STATEMENT_CACHE]); if ($pdoConnectionStr[-1] != ":") { $pdoConnectionStr .= ";"; } $pdoConnectionStr .= http_build_query($queryArr, "", ";"); return $pdoConnectionStr; } public function __destruct() { $this->disconnect(); } /** * @param string $sql * @param array $array * @return PDOStatement */ protected function getDBStatement($sql, $array = null) { if (is_null($this->connectionUri->getQueryPart(self::DONT_PARSE_PARAM))) { list($sql, $array) = SqlBind::parseSQL($this->connectionUri, $sql, $array); } if ($this->useStmtCache) { if ($this->getMaxStmtCache() > 0 && !isset($this->stmtCache[$sql])) { $this->stmtCache[$sql] = $this->getInstance()->prepare($sql); if ($this->getCountStmtCache() > $this->getMaxStmtCache()) { //Kill old cache to get waste memory array_shift($this->stmtCache); } } $this->isConnected(true, true); $stmt = $this->stmtCache[$sql]; } else { $stmt = $this->getInstance()->prepare($sql); } if (!empty($array)) { foreach ($array as $key => $value) { $stmt->bindValue(":" . SqlBind::keyAdj($key), $value); } } $this->logger->debug("SQL: $sql\nParams: " . json_encode($array)); return $stmt; } public function getIterator($sql, $params = null, CacheInterface $cache = null, $ttl = 60) { if (!empty($cache)) { // Otherwise try to get from cache $key = $this->getQueryKey($sql, $params); // Get the CACHE $cachedItem = $cache->get($key); if (!is_null($cachedItem)) { return (new ArrayDataset($cachedItem))->getIterator(); } } $stmt = $this->getDBStatement($sql, $params); $stmt->execute(); $iterator = new DbIterator($stmt); if (!empty($cache)) { $cachedItem = $iterator->toArray(); $cache->set($key, $cachedItem, $ttl); return (new ArrayDataset($cachedItem))->getIterator(); } return $iterator; } public function getScalar($sql, $array = null) { $stmt = $this->getDBStatement($sql, $array); $stmt->execute(); $scalar = $stmt->fetchColumn(); $stmt->closeCursor(); return $scalar; } public function getAllFields($tablename) { $fields = array(); $statement = $this->getInstance()->query( SqlHelper::createSafeSQL( "select * from @@table where 0=1", [ "@@table" => $tablename ] ) ); $fieldLength = $statement->columnCount(); for ($i = 0; $i < $fieldLength; $i++) { $fld = $statement->getColumnMeta($i); $fields[] = strtolower($fld ["name"]); } return $fields; } public function beginTransaction() { $this->logger->debug("SQL: Begin transaction"); $this->getInstance()->beginTransaction(); } public function commitTransaction() { $this->logger->debug("SQL: Commit transaction"); $this->getInstance()->commit(); } public function rollbackTransaction() { $this->logger->debug("SQL: Rollback transaction"); $this->getInstance()->rollBack(); } public function execute($sql, $array = null) { $stmt = $this->getDBStatement($sql, $array); $result = $stmt->execute(); if ($this->isSupportMultRowset()) { // Check error do { // This loop is only to throw an error (if exists) // in case of execute multiple queries } while ($stmt->nextRowset()); } return $result; } public function executeAndGetId($sql, $array = null) { return $this->getDbHelper()->executeAndGetInsertedId($this, $sql, $array); } /** * @return PDO */ public function getDbConnection() { return $this->instance; } public function getAttribute($name) { $this->getInstance()->getAttribute($name); } public function setAttribute($name, $value) { $this->getInstance()->setAttribute($name, $value); } public function getDbHelper() { if (empty($this->dbHelper)) { $this->dbHelper = Factory::getDbFunctions($this->connectionUri); } return $this->dbHelper; } public function getUri() { return $this->connectionUri; } /** * @return bool */ public function isSupportMultRowset() { return $this->supportMultRowset; } /** * @param bool $multipleRowSet */ public function setSupportMultRowset($multipleRowSet) { $this->supportMultRowset = $multipleRowSet; } /** * @return int */ public function getMaxStmtCache() { return $this->maxStmtCache; } public function getCountStmtCache() { return count($this->stmtCache); } /** * @param int $maxStmtCache */ public function setMaxStmtCache($maxStmtCache) { $this->maxStmtCache = $maxStmtCache; } public function isConnected($softCheck = false, $throwError = false) { if (empty($this->instance)) { if ($throwError) { throw new DbDriverNotConnected('DbDriver not connected'); } return false; } if ($softCheck) { return true; } try { $this->instance->query("SELECT 1"); // Do not use $this->getInstance() } catch (Exception $ex) { if ($throwError) { throw new DbDriverNotConnected('DbDriver not connected'); } return false; } return true; } protected function getInstance() { $this->isConnected(true, true); return $this->instance; } public function enableLogger(LoggerInterface $logger) { $this->logger = $logger; } public function log($message, $context = []) { $this->logger->debug($message, $context); } }__halt_compiler();----SIGNATURE:----aMTaq7FKLis8zX3q+wljJcPkBFNYyiDD0K2m+G3z18G4UqjIWvp16ZGoH9Eufoo3eX4K0v5RGi9YjDZ8avbu/RSOYg644lYx0re9wlE7XmpAeNVQgeJIKT2EpGOHjFCrw82QV79YGSVy19vxWnCJPHsHo7DsIzBuFlftA3qhc9ALqqZ/oR917x2+60olTGRHBOS4mpPcczom9yLzxllXo8iY9/2G2RWdG7jRbJqSqr9Caht4JSQwC6cAo5wreNkGGfBCPFrodtID1wC0uzNng3FTMSGxe4OSHhurZugP9qxh3MoTUMppLn8TjmSW/3Sc77FQE3mr2L2Zi53aUagKDkIZ02a5zq3xJsqTbVwIjbEkOpQEeYFAzIXqr75m7C94Rey2PdqrKXb0dIcTVZEpjKbEjdjMvOcOYUg8E+BbZu+4DXZCyinHcLY05D5RkU6jOP4+O7dlWJ0KYpIxY3un5Pcplcc+t1PbvAJxtSWcLuYwuglHbPDryonSpjWEAPukYO58kgEg6mq9x6cOxz9xQKepZeyY4medZ1ewLy11O/XLfQT0U4cbhnJOC7GYuFjANWyANr3wm6IqCTjm5dKmikB7RYqoOlFGCOr3wSfG8SD6HpCcmd+vbOKKhGit5kytDZ2xRiGrw0wFTf0Aez6lb8xkfjVF8uXNqEce7jYMFrY=----ATTACHMENT:----NTU5MDMwOTk2ODkxNDI2OCA4MjE2MzM5OTQ1NTc3NTk2IDg0ODM2NTIxNTMyODk2MzU=