Exemplo n.º 1
0
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     $dbHost = $this->dbHost;
     $dbPort = 0;
     if (($pos = strpos($dbHost, ":")) !== false) {
         $dbPort = intval(substr($dbHost, $pos + 1));
         $dbHost = substr($dbHost, 0, $pos);
     }
     if (($this->dbOptions & self::PERSISTENT) != 0) {
         $dbHost = "p:" . $dbHost;
     }
     /** @var $connection \mysqli */
     $connection = \mysqli_init();
     if (!$connection) {
         throw new ConnectionException('Mysql init failed');
     }
     if (!empty($this->dbInitCommand)) {
         if (!$connection->options(MYSQLI_INIT_COMMAND, $this->dbInitCommand)) {
             throw new ConnectionException('Setting mysql init command failed');
         }
     }
     if ($dbPort > 0) {
         $r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName, $dbPort);
     } else {
         $r = $connection->real_connect($dbHost, $this->dbLogin, $this->dbPassword, $this->dbName);
     }
     if (!$r) {
         throw new ConnectionException('Mysql connect error', sprintf('(%s) %s', $connection->connect_errno, $connection->connect_error));
     }
     $this->resource = $connection;
     $this->isConnected = true;
     // nosql memcached driver
     if (isset($this->configuration['memcache'])) {
         $memcached = \Freetrix\Main\Application::getInstance()->getConnectionPool()->getConnection($this->configuration['memcache']);
         mysqlnd_memcache_set($this->resource, $memcached->getResource());
     }
     //global $DB, $USER, $APPLICATION;
     if ($fn = \Freetrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
Exemplo n.º 2
0
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     if (($this->dbOptions & self::PERSISTENT) != 0) {
         $connection = oci_pconnect($this->dbLogin, $this->dbPassword, $this->dbName);
     } else {
         $connection = oci_connect($this->dbLogin, $this->dbPassword, $this->dbName);
     }
     if (!$connection) {
         throw new ConnectionException('Oracle connect error', $this->getErrorMessage());
     }
     $this->isConnected = true;
     $this->resource = $connection;
     /** @noinspection PhpUnusedLocalVariableInspection */
     global $DB, $USER, $APPLICATION;
     if ($fn = \Freetrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
Exemplo n.º 3
0
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     if (($this->dbOptions & self::PERSISTENT) != 0) {
         $connection = mysql_pconnect($this->dbHost, $this->dbLogin, $this->dbPassword);
     } else {
         $connection = mysql_connect($this->dbHost, $this->dbLogin, $this->dbPassword, true);
     }
     if (!$connection) {
         throw new ConnectionException('Mysql connect error', mysql_error());
     }
     if (!mysql_select_db($this->dbName, $connection)) {
         throw new ConnectionException('Mysql select db error', mysql_error($connection));
     }
     $this->resource = $connection;
     $this->isConnected = true;
     if ($fn = \Freetrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
Exemplo n.º 4
0
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     $connectionInfo = array("UID" => $this->dbLogin, "PWD" => $this->dbPassword, "Database" => $this->dbName, "ReturnDatesAsStrings" => true);
     if (($this->dbOptions & self::PERSISTENT) != 0) {
         $connectionInfo["ConnectionPooling"] = true;
     } else {
         $connectionInfo["ConnectionPooling"] = false;
     }
     $connection = sqlsrv_connect($this->dbHost, $connectionInfo);
     if (!$connection) {
         throw new ConnectionException('MS Sql connect error', $this->getErrorMessage());
     }
     $this->resource = $connection;
     $this->isConnected = true;
     // hide cautions
     sqlsrv_configure("WarningsReturnAsErrors", 0);
     global $DB, $USER, $APPLICATION;
     if ($fn = \Freetrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
Exemplo n.º 5
0
 public static function clearCache($full = false, $initDir = "")
 {
     if ($full !== true && $full !== false && $initDir === "" && is_string($full)) {
         $initDir = $full;
         $full = true;
     }
     $res = true;
     if ($full === true) {
         $obCache = static::createInstance();
         $obCache->cleanDir($initDir, "cache");
     }
     $path = Main\Loader::getPersonal("cache" . $initDir);
     if (is_dir($path) && ($handle = opendir($path))) {
         while (($file = readdir($handle)) !== false) {
             if ($file === "." || $file === "..") {
                 continue;
             }
             if (is_dir($path . "/" . $file)) {
                 if (!static::clearCache($full, $initDir . "/" . $file)) {
                     $res = false;
                 } else {
                     @chmod($path . "/" . $file, FX_DIR_PERMISSIONS);
                     //We suppress error handle here because there may be valid cache files in this dir
                     @rmdir($path . "/" . $file);
                 }
             } elseif ($full) {
                 @chmod($path . "/" . $file, FX_FILE_PERMISSIONS);
                 if (!unlink($path . "/" . $file)) {
                     $res = false;
                 }
             } elseif (substr($file, -4) === ".php") {
                 $c = static::createInstance();
                 if ($c->isCacheExpired($path . "/" . $file)) {
                     @chmod($path . "/" . $file, FX_FILE_PERMISSIONS);
                     if (!unlink($path . "/" . $file)) {
                         $res = false;
                     }
                 }
             } else {
                 //We should skip unknown file
                 //it will be deleted with full cache cleanup
             }
         }
         closedir($handle);
     }
     return $res;
 }