Home >Backend Development >PHP Tutorial >Mysql数据库的反复connect与close问题

Mysql数据库的反复connect与close问题

WBOY
WBOYOriginal
2016-06-06 20:17:171988browse

用php开发app API,每个API大致实现一个功能,但每个功能都需要和Mysql数据库通信。app使用过程中每次访问API是否都需要connect Mysql?这样反复链接与断开会不会影响数据查询的性能呢?

回复内容:

用php开发app API,每个API大致实现一个功能,但每个功能都需要和Mysql数据库通信。app使用过程中每次访问API是否都需要connect Mysql?这样反复链接与断开会不会影响数据查询的性能呢?

单例模式去写这个数据库操作类

<code>public static function getConn($database) {
        static $singletons = array();
        !isset($singletons[$database]) && $singletons[$database] = new Database($database);
        return $singletons[$database];
    }</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn