本文整理汇总了PHP中DatabaseBase::isOpen方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::isOpen方法的具体用法?PHP DatabaseBase::isOpen怎么用?PHP DatabaseBase::isOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::isOpen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rotateDb
/**
* Drop the database connection $this->db and try to get a new one.
*
* This function tries to get a /different/ connection if this is
* possible. Hence, (if this is possible) it switches to a different
* failover upon each call.
*
* This function resets $this->lb and closes all connections on it.
*
* @throws MWException
*/
function rotateDb()
{
// Cleaning up old connections
if (isset($this->lb)) {
$this->lb->closeAll();
unset($this->lb);
}
if ($this->forcedDb !== null) {
$this->db = $this->forcedDb;
return;
}
if (isset($this->db) && $this->db->isOpen()) {
throw new MWException('DB is set and has not been closed by the Load Balancer');
}
unset($this->db);
// Trying to set up new connection.
// We do /not/ retry upon failure, but delegate to encapsulating logic, to avoid
// individually retrying at different layers of code.
// 1. The LoadBalancer.
try {
$this->lb = wfGetLBFactory()->newMainLB();
} catch (Exception $e) {
throw new MWException(__METHOD__ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")");
}
// 2. The Connection, through the load balancer.
try {
$this->db = $this->lb->getConnection(DB_SLAVE, 'dump');
} catch (Exception $e) {
throw new MWException(__METHOD__ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")");
}
}