validateConnUri($connUri); $strcnn = $this->createPdoConnStr($connUri); $this->createPdoInstance($strcnn, $preOptions, $postOptions); } protected function createPdoInstance($pdoConnectionString, $preOptions = null, $postOptions = null) { $this->instance = new PDO( $pdoConnectionString, $this->connectionUri->getUsername(), $this->connectionUri->getPassword(), (array) $preOptions ); $this->connectionUri = $this->connectionUri->withScheme($this->instance->getAttribute(PDO::ATTR_DRIVER_NAME)); $this->setPdoDefaultParams($postOptions); } /** * @param Uri $connUri * @param string $scheme * @throws NotAvailableException */ protected function validateConnUri($connUri, $scheme = null) { $this->connectionUri = $connUri; if (!defined('PDO::ATTR_DRIVER_NAME')) { throw new NotAvailableException("Extension 'PDO' is not loaded"); } if (empty($scheme)) { $scheme = $connUri->getScheme(); } if (!extension_loaded('pdo_' . strtolower($scheme))) { throw new NotAvailableException("Extension 'pdo_" . strtolower($connUri->getScheme()) . "' is not loaded"); } if ($connUri->getQueryPart(self::STATEMENT_CACHE) == "true") { $this->useStmtCache = true; } } protected function setPdoDefaultParams($postOptions = []) { $this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->instance->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); foreach ((array) $postOptions as $key => $value) { $this->instance->setAttribute($key, $value); } } protected function createPdoConnStr(Uri $connUri) { $host = $connUri->getHost(); if (empty($host)) { return $connUri->getScheme() . ":" . $connUri->getPath(); } $database = preg_replace('~^/~', '', $connUri->getPath()); if (!empty($database)) { $database = ";dbname=$database"; } $strcnn = $connUri->getScheme() . ":" . "host=" . $connUri->getHost() . $database; if ($connUri->getPort() != "") { $strcnn .= ";port=" . $connUri->getPort(); } $query = $connUri->getQuery(); $queryArr = explode('&', $query); foreach ($queryArr as $value) { if ((strpos($value, self::DONT_PARSE_PARAM . "=") === false) && (strpos($value, self::STATEMENT_CACHE . "=") === false)) { $strcnn .= ";" . $value; } } return $strcnn; } public function __destruct() { $this->stmtCache = null; $this->instance = null; } /** * @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->instance->prepare($sql); if ($this->getCountStmtCache() > $this->getMaxStmtCache()) { //Kill old cache to get waste memory array_shift($this->stmtCache); } } $stmt = $this->stmtCache[$sql]; } else { $stmt = $this->instance->prepare($sql); } if (!empty($array)) { foreach ($array as $key => $value) { $stmt->bindValue(":" . SqlBind::keyAdj($key), $value); } } return $stmt; } public function getIterator($sql, $params = null) { $stmt = $this->getDBStatement($sql, $params); $stmt->execute(); return new DbIterator($stmt); } 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->instance->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->instance->beginTransaction(); } public function commitTransaction() { $this->instance->commit(); } public function rollbackTransaction() { $this->instance->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->instance->getAttribute($name); } public function setAttribute($name, $value) { $this->instance->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; } } __halt_compiler();----SIGNATURE:----I2h1fsYDG6FiLtaHNp8eJb2X0mvz7EBOVYIrMRq2rgrzvOVBtjHrbM9IBcJYAh+XxgTvQqXA2Se9LLSBZwrTGUh29JOEylzKLP1KgXxYz7GBSagxvIoYWeh33ZHhjGZ/FAJAC3NQpFqg2P4/lbemP+sNxGXU6ftVlToG1vaivCNozdQehJ7MLIilGE9WtFyY/zP5uX0tPsBQHfby7HEFTy9Dx/6zgY0jlGMXYrdQ/UMSCCbdVXF0vlpF+zql1IjebJ1mOzLf6HtlqkyR0nF9voESr5NbuNcXIUlGRsEV7r9ioHcoBJjipPJI+rcuUzxkvX1WEXSzeGixO17jP2ro7Pjh78Q7Pa/RBTokymdhTzCXALU/sXNubJh+QkQ9m5iy4BUnxHU7ezqu72rullZMMtZ6Lkx9C71pq7dpMdnQ6nahptMDVH2nhcCSJCcHXRo4EimlY0lg45BMPedk/L53yNZ7/PklFi3u6fhtHBYzqc4UDE2WjUce1eX+PYxRb+fPPYLxTrDi3OUIFE6rHbiNp8KEUVo9DKbgKltycPthQItiyFloj66ucYyfWDR9XD6Xgez2ONFlMUAuXQOuoo4Ad3z7o2UM4Js7kKs02MY0fagdlzriQREk82ctqhMzxDqfCUEu+5DnrIcCUAxT03PSZPM7ft1Acav9FQljEXW/0zM=----ATTACHMENT:----ODQwODQ5Njc4MzQ2NzU3OSA5MzE5NzQyNTI4ODQyNTI0IDUyMzU1MDU5MTg4OTA1NzY=