作者:wqgysxy | 来源:互联网 | 2018-05-16 11:58
用php开发appAPI,每个API大致实现一个功能,但每个功能都需要和Mysql数据库通信。app使用过程中每次访问API是否都需要connectMysql?这样反复链接与断开会不会影响数据查询的性能呢?
用php开发app API,每个API大致实现一个功能,但每个功能都需要和Mysql数据库通信。app使用过程中每次访问API是否都需要connect Mysql?这样反复链接与断开会不会影响数据查询的性能呢?
回复内容:
用php开发app API,每个API大致实现一个功能,但每个功能都需要和Mysql数据库通信。app使用过程中每次访问API是否都需要connect Mysql?这样反复链接与断开会不会影响数据查询的性能呢?
单例模式去写这个数据库操作类
public static function getConn($database) {
static $singletOns= array();
!isset($singletons[$database]) && $singletons[$database] = new Database($database);
return $singletons[$database];
}