数据库与php交互 数据库和php的连接( 二 )


}else {
require './utils.php';
}// 初始化 配置文件信息
$this-dbconfig = XMLUtil::getDBConfiguration ();// 准备好数据库连接池“伪队列”
$this-poolsize = $poolsize;
$this-dbpool = array ();for($index = 1; $index = $this-poolsize; $index ++) {
$conn = mysqli_connect ( $this-dbconfig ['host'], $this-dbconfig ['user'], $this-dbconfig ['password'], $this-dbconfig ['db'] ) or die ( "mark连接数据库失败!/markbr /" );
array_push ( $this-dbpool, $conn );
}
}/**
* 从数据库连接池中获取一个数据库链接资源
*
* @throws ErrorException
* @return mixed
*/
public function getConn() {if (count ( $this-dbpool ) = 0) {throw new ErrorException ( "mark数据库连接池中已无链接资源,请稍后重试!/mark" );
} else {return array_pop ( $this-dbpool );
}
}/**
* 将用完的数据库链接资源放回到数据库连接池
*
* @param unknown $conn
* @throws ErrorException
*/
public function release($conn) {if (count ( $this-dbpool ) = $this-poolsize) {throw new ErrorException ( "mark数据库连接池已满/markbr /" );
} else {
array_push ( $this-dbpool, $conn );
}
}
}
【数据库与php交互 数据库和php的连接】数据库与php交互的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于数据库和php的连接、数据库与php交互的信息别忘了在本站进行查找喔 。

推荐阅读