Home  >  Article  >  Backend Development  >  敢问各位大侠,php连接mysql的时候应该使用静态方法还是非静态方法?解决方法

敢问各位大侠,php连接mysql的时候应该使用静态方法还是非静态方法?解决方法

WBOY
WBOYOriginal
2016-06-13 10:20:121086browse

敢问各位大侠,php连接mysql的时候应该使用静态方法还是非静态方法?
哪个比较好一些,多谢各位了

------解决方案--------------------
都可以吧。
------解决方案--------------------
应该使用动态方法,理由如下:
1、静态方法只能访问静态属性,会给其他方法带来不便
2、在你的应用中可能会使用到多个数据库连接,使用动态方法时,只需再实例化一个对象
3、在绝大多数应用中,数据库操作并不是单独存在的。一般是与业务逻辑一起封装成类的。

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