reconnection to DB server
@param mixed|MySQL $obj
@return bool
979160
public function reconnection($obj): bool
    {
        $resId = $this->genID($obj);
        $info  = $this->getMeta($resId);

        if (!$obj->connect($info)) {
            $this->destroy($obj);
            return false;
        }

        return true;
    }
1069432
private function applyTransaction($obj)
    {
        if(null !== $this->str_next_transaction) {
            $obj->setTransaction($this->str_next_transaction);
            $this->str_next_transaction = null;
        }
        return $obj;
    }
479215
protected function checkConnection($reconnect = false)
        {
            if(empty($this->_lnk)) {
                $this->log('CheckConnection: link is not valid');
                if($reconnect) {
                    $this->log('CheckConnection: try to reconnect');
                    $this->_lnk = @odbc_connect('Driver=' . VERTICA_DRIVER . ';Servername=' . VERTICA_SERVER . ';Database='.VERTICA_DATABASE, VERTICA_USER_ETL, VERTICA_PASS_ETL);
                    if(!$this->_lnk) {
                        $this->log('CheckConnection: reconnect failed');
                        throw new Exception('Connection failed or gone away and can\'t reconnect - '.odbc_errormsg($this->_link), self::CONNECTION_FAILED);
                    }
                    $this->log('CheckConnection: reconnected!');
                    return;
                }
                throw new Exception('Connection failed or gone away - ' . odbc_errormsg($this->_link), self::CONNECTION_FAILED);
            }
        }
979029
public function initializeObject($obj)
    {
        if ($obj instanceof Proxy) {
            $obj->__load();

            return;
        }

        if ($obj instanceof PersistentCollection) {
            $obj->initialize();
        }
    }
198227
public function Delete($obj)
	{
		$objectclass = get_class($obj);

		if (!$obj->OnBeforeDelete())
		{
			$this->Observe("Delete was cancelled because OnBeforeDelete did not return true");
			return 0;
		}

		$fms = $this->GetFieldMaps($objectclass);

		$pk = $obj->GetPrimaryKeyName();
		$id = $obj->$pk;
		$table = $fms[$pk]->TableName;
		$pkcol = $fms[$pk]->ColumnName;

		$sql = "delete from `$table` where `$pkcol` = '" . $this->Escape($id) . "'";
		$returnval = $this->DataAdapter->Execute($sql);

		// remove from cache
		$this->DeleteCache($objectclass,$id);

		$obj->OnDelete(); // fire OnDelete event

		return $returnval;

	}
1115534
protected function validate($obj): bool
    {
        $time  = \time();
        $resId = $this->genID($obj);

        if (!$meta = $this->getMeta($resId)) {
            $this->destroy($obj);
            return false;
        }

        // check max lifetime
        $lifetime = $this->maxLifetime * 60;
        if ($time - $meta['createAt'] >= $lifetime) {
            $this->destroy($obj);
            return false;
        }

        // if lost connection, reconnection it.
        if (!$obj->connected) {
            return $this->reconnection($obj);
        }

        return true;
    }
836301
protected function reconnect()
    {
        if ($this->connection->inTransaction()) {
            // It is not safe to blindly reconnect in the middle of a transaction
            return false;
        }

        try {
            // Make sure we free any resources associated with the old connection
            $this->connection->disconnect();
        } catch (Exception $e) {
        }

        try {
            $this->connection->connect();
            $this->connection->log('[RECONNECT]');

            return true;
        } catch (Exception $e) {
            // If there was an error connecting again, don't report it back,
            // let the retry handler do it.
            return false;
        }
    }
1070236
protected function reconnect($key, $database)
    {
        $connections = DB::getConnections();
        /** @var MySqlConnection $connection */
        $connection = isset($connections[$key]) ? $connections[$key] : '';

        if (is_object($connection) && $connection->getDatabaseName() != $database) {
            $connection->setDatabaseName($database);
            $connection->reconnect();
        }
    }
440559
public function disconnect()
	{
		//check if there is a valid connection instance
		if ($this->validService() ) 
		{
			//set the connection status to false
			$this->connected = false; 

			//call method to disconnect from database
			$this->service->close();

		}

		//return this instance after disconnection 
		return $this;

	}
1214829
public function load($obj, $cacheupd = false) {
		if (DEBUG_MODE) {
			BLog::addToLog('[Users.Session]: Load()');
		}

		$enddate = new \DateTime($obj['end']);
		$nowdate = new \DateTime();
		$lacdate = new \DateTime($obj['lastaction']);
		if (DEBUG_MODE) {
			BLog::addToLog('[Users.Session]: Load() enddate=' . $enddate->format('Y-m-d H:i:s'));
			BLog::addToLog('[Users.Session]: Load() nowdate=' . $nowdate->format('Y-m-d H:i:s'));
			BLog::addToLog('[Users.Session]: Load() lacdate=' . $lacdate->format('Y-m-d H:i:s'));
		}
		if (!is_string($obj['sessionid'])) {
			if (DEBUG_MODE) {
				BLog::addToLog('[Users.Session]: Load() sessionid is not a string!', LL_ERROR);
			}
			$this->sessionid = '';
			$this->close();
			return false;
		}
		if ($enddate < $nowdate) {
			if (DEBUG_MODE) {
				BLog::addToLog('[Users.Session]: Load() $enddate<$nowdate. Closing session.', LL_ERROR);
			}
			$this->sessionid = $obj['sessionid'];
			$this->close();
			return false;
		}
		if (($nowdate->getTimestamp() - $lacdate->getTimestamp()) > $obj['updatestep']) {
			if (!$db = BFactory::getDBO()) {
				return false;
			}
			$qr = 'update sessions set 
			     `end`=DATE_ADD(now(),INTERVAL ' . $obj['interval'] . ' SECOND),
			     lastaction=NOW()
			     WHERE sessionid=' . $db->escapeString($obj['sessionid']);
			$q = $db->Query($qr);
			if (empty($q)) {
				return false;
			}

			$qr = 'update users set last_action=NOW() where id=' . $obj['userid'];
			$q = $db->Query($qr);
			$busers = BUsers::getInstance();
			$me = $busers->itemGet($obj['userid']);
			if (!empty($me)) {
				$me->updatecache();
			}
			$lacdate = $nowdate;
			$enddate->add(new \DateInterval('PT' . $obj['interval'] . 'S'));
			$cacheupd = true;
		}
		$this->sessionid = $obj['sessionid'];
		$this->ipv4 = $obj['ipv4'];
		$this->start = new \DateTime($obj['start']);
		$this->end = $enddate;
		$this->lastaction = $lacdate;//->format("Y-m-d H:i:s");
		$this->userid = $obj['userid'];
		$this->data = unserialize($obj['data']);
		$this->updatestep = $obj['updatestep'];
		$this->interval = $obj['interval'];
		if (CACHE_TYPE && $cacheupd) {
			$obj['end'] = $this->end->format("Y-m-d H:i:s");;
			$obj['lastaction'] = $this->lastaction->format("Y-m-d H:i:s");;
			$bCache = BFactory::getCache();
			$bCache->set('session:' . $obj['sessionid'], $obj, 600);
		}
		return true;
	}
1232292
public function db_connect($persistent = FALSE)
	{
		return ($persistent === TRUE)
			? odbc_pconnect($this->dsn, $this->username, $this->password)
			: odbc_connect($this->dsn, $this->username, $this->password);
	}
929973
public function Equals( $obj )
	{
		if ( ! $obj instanceof GMonthDayValue )
		{
			return false;
		}

		/**
		 * @var DateTimeValueBase $other
		 */
		$other = $obj;
		return $this->ToString( null ) == $other->ToString( null );
	}
443975
public function fetch_object($sql)
    {

        if (empty($sql)) return false;

        $res    = $this->query($sql);
        $result = @mysql_fetch_object($res);
        $this->free($res);

        return $result;
    }
1269547
public function Equals($obj)
	{
		if ( ! $obj instanceof IDValue )
		{
			return false;
		}

		/**
		 * @var TokenValue $other
		 */
		$other = $obj;
		return strcmp( $this->Value, $other->Value ) == 0;
	}
880883
public function Equals( $obj )
	{
		if ( ! $obj instanceof DurationValue )
		{
			return false;
		}

		/**
		 * @var DurationValue $other
		 */
	    $other = $obj;

		if ( $other->getIsZero() && $this->getIsZero())
			return true;

		if ( $this->getType() != $other->getType() ) return false;

		return $this->ToString() == $other->ToString();
	}
575478
private function connect($status)
    {
        if ($status === true) {
            $setting = $this->settings;

            return $db = new \PDO('mysql:host='.__config()->database->mysql_host, __config()->database->mysql_user, __config()->database->mysql_pass);
        }
        if ($status === false) {
            return $db = null;
        }
    }
334864
protected function resolved($obj)
	{
		if( ! is_object($obj) )
		{
			return true;
		}

		$data = get_object_vars($obj);
		if( count($data) == 2
			&& array_key_exists('id', $data)
			&& array_key_exists('type', $data)
		)
		{
			return false;
		}

		return true;
	}