yii\db\Connection::getSlavePdo PHP Method

getSlavePdo() public method

When [[enableSlaves]] is true, one of the slaves will be used for read queries, and its PDO instance will be returned by this method.
public getSlavePdo ( boolean $fallbackToMaster = true ) : PDO
$fallbackToMaster boolean whether to return a master PDO in case none of the slave connections is available.
return PDO the PDO instance for the currently active slave connection. Null is returned if no slave connection is available and `$fallbackToMaster` is false.
    public function getSlavePdo($fallbackToMaster = true)
    {
        $db = $this->getSlave(false);
        if ($db === null) {
            return $fallbackToMaster ? $this->getMasterPdo() : null;
        } else {
            return $db->pdo;
        }
    }