Final Class Yiisoft\Db\Connection\ConnectionProvider
| Inheritance | Yiisoft\Db\Connection\ConnectionProvider |
|---|
ConnectionProvider is used to manage DB connections.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| all() | Returns all connections. | Yiisoft\Db\Connection\ConnectionProvider |
| clear() | Clears all connections. | Yiisoft\Db\Connection\ConnectionProvider |
| get() | Returns a connection by name. | Yiisoft\Db\Connection\ConnectionProvider |
| has() | Checks if a connection with the given name exists. | Yiisoft\Db\Connection\ConnectionProvider |
| remove() | Removes a connection by name. | Yiisoft\Db\Connection\ConnectionProvider |
| set() | Sets a connection by name. | Yiisoft\Db\Connection\ConnectionProvider |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT | 'default' | Yiisoft\Db\Connection\ConnectionProvider |
Method Details
Returns all connections.
| public static Yiisoft\Db\Connection\ConnectionInterface[] all ( ) |
public static function all(): array
{
return self::$connections;
}
Clears all connections.
| public static void clear ( ) |
public static function clear(): void
{
self::$connections = [];
}
Returns a connection by name.
| public static Yiisoft\Db\Connection\ConnectionInterface get ( string $name = self::DEFAULT ) | ||
| $name | string | |
public static function get(string $name = self::DEFAULT): ConnectionInterface
{
return self::$connections[$name]
?? throw new InvalidArgumentException("Connection with name '$name' does not exist.");
}
Checks if a connection with the given name exists.
| public static boolean has ( string $name = self::DEFAULT ) | ||
| $name | string | |
public static function has(string $name = self::DEFAULT): bool
{
return isset(self::$connections[$name]);
}
Removes a connection by name.
| public static void remove ( string $name = self::DEFAULT ) | ||
| $name | string | |
public static function remove(string $name = self::DEFAULT): void
{
unset(self::$connections[$name]);
}
Sets a connection by name.
| public static void set ( Yiisoft\Db\Connection\ConnectionInterface $connection, string $name = self::DEFAULT ) | ||
| $connection | Yiisoft\Db\Connection\ConnectionInterface | |
| $name | string | |
public static function set(ConnectionInterface $connection, string $name = self::DEFAULT): void
{
self::$connections[$name] = $connection;
}
Signup or Login in order to comment.