InfluxDB\Client::fromDSN PHP 메소드

fromDSN() 공개 정적인 메소드

https+influxdb://username:pass@localhost:8086/databasename udp+influxdb://username:pass@localhost:4444/databasename
public static fromDSN ( string $dsn, integer $timeout, boolean $verifySSL = false ) : Client | Database
$dsn string
$timeout integer
$verifySSL boolean
리턴 Client | Database
    public static function fromDSN($dsn, $timeout = 0, $verifySSL = false)
    {
        $connParams = parse_url($dsn);
        $schemeInfo = explode('+', $connParams['scheme']);
        $dbName = null;
        $modifier = null;
        $scheme = $schemeInfo[0];
        if (isset($schemeInfo[1])) {
            $modifier = strtolower($schemeInfo[0]);
            $scheme = $schemeInfo[1];
        }
        if ($scheme != 'influxdb') {
            throw new ClientException($scheme . ' is not a valid scheme');
        }
        $ssl = $modifier === 'https' ? true : false;
        $dbName = $connParams['path'] ? substr($connParams['path'], 1) : null;
        $client = new self($connParams['host'], $connParams['port'], isset($connParams['user']) ? $connParams['user'] : '', isset($connParams['pass']) ? $connParams['pass'] : '', $ssl, $verifySSL, $timeout);
        // set the UDP driver when the DSN specifies UDP
        if ($modifier == 'udp') {
            $client->setDriver(new UDP($connParams['host'], $connParams['port']));
        }
        return $dbName ? $client->selectDB($dbName) : $client;
    }

Usage Example

 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     // directly get the database object
     $dsn = 'influxdb://';
     if ($username) {
         $dsn .= sprintf("%s:%s@", $username, $password);
     }
     if ($params["host"]) {
         $dsn .= $params["host"];
     } else {
         $dsn .= 'localhost';
     }
     if ($params["port"]) {
         $dsn .= ':' . $params["port"];
     } else {
         $dsn .= ':8086';
     }
     if ($params["dbname"]) {
         $dsn .= '/' . $params["dbname"];
     } else {
         $dsn .= '/';
     }
     $this->database = Client::fromDSN($dsn);
     $this->client = $this->database->getClient();
 }
All Usage Examples Of InfluxDB\Client::fromDSN