yii\db\Connection::getSlavePdo PHP 메소드

getSlavePdo() 공개 메소드

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.
리턴 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;
        }
    }