function PdoStore::__construct
You can either pass an existing database connection as PDO instance or a DSN string that will be used to lazy-connect to the database when the lock is actually used.
List of available options:
- db_table: The name of the table [default: lock_keys]
- db_id_col: The column where to store the lock key [default: key_id]
- db_token_col: The column where to store the lock token [default: key_token]
- db_expiration_col: The column where to store the expiration [default: key_expiration]
- db_username: The username when lazy-connect [default: '']
- db_password: The password when lazy-connect [default: '']
- db_connection_options: An array of driver-specific connection options [default: []]
Parameters
array $options An associative array of options:
float $gcProbability Probability expressed as floating number between 0 and 1 to clean old locks:
int $initialTtl The expiration delay of locks in seconds:
Throws
InvalidArgumentException When first argument is not PDO nor Connection nor string
InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
InvalidArgumentException When the initial ttl is not valid
File
-
vendor/
symfony/ lock/ Store/ PdoStore.php, line 67
Class
- PdoStore
- PdoStore is a PersistingStoreInterface implementation using a PDO connection.
Namespace
Symfony\Component\Lock\StoreCode
public function __construct(\PDO|string $connOrDsn, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300) {
$this->init($options, $gcProbability, $initialTtl);
if ($connOrDsn instanceof \PDO) {
if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
throw new InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
}
$this->conn = $connOrDsn;
}
else {
$this->dsn = $connOrDsn;
}
$this->username = $options['db_username'] ?? $this->username;
$this->password = $options['db_password'] ?? $this->password;
$this->connectionOptions = $options['db_connection_options'] ?? $this->connectionOptions;
}