php跨框架调用方法,PHP框架一个方法调用的疑惑,贴出全部代码

请问class mysql 调用的_getInstance方法 在哪里定义的?贴出了全部代码

namespace LaneSmartFW\DB;

/**

* 基础Model类,所有的Model文件均继承本类

* Created by lixuan-it@360.cn

* User: lane

* Date: 15/8/27

* Time: 下午6:35

* E-mail: lixuan868686@163.com

* WebSite: http://www.lanecn.com

*/

class Model implements DbInterface {

protected $dbConfigKey = null;

private $_db = null;

private function _getInstance(){

if(is_null($this->_db)){

if(is_null($this->dbConfigKey)){

$this->_db = Db::factor();

}else{

$this->_db = Db::factor($this->dbConfigKey);

}

}

return $this->_db;

}

public function close(){

$this->_getInstance()->close();

}

public function query($sql){

return $this->_getInstance()->query($sql);

}

public function fetchAssoc($resource){

return $this->_getInstance()->fetchAssoc($resource);

}

public function select($sql){

return $this->_getInstance()->select($sql);

}

}

namespace LaneSmartFW\DB;

/**

* Created by lixuan-it@360.cn

* User: lane

* Date: 15/8/27

* Time: 下午3:29

* E-mail: lixuan868686@163.com

* WebSite: http://www.lanecn.com

*/

class Mysql implements DbInterface{

private $_conn = null;

public function __construct($dbConfigKey='DB_CONFIG'){

if(is_null($this->_conn)){

$this->_connect($dbConfigKey);

}

}

private function _connect($dbConfigKey='DB_CONFIG'){

$dbConfig = getConfig($dbConfigKey);

$this->_conn = mysqli_connect($dbConfig['DB_HOST'], $dbConfig['DB_USERNAME'], $dbConfig['DB_PASSWORD'], $dbConfig['DB_NAME'], $dbConfig['DB_PORT']);

}

public function close(){

mysqli_close($this->_getInstance());

}

public function query($sql){

$result = mysqli_query($this->_conn, $sql);

return $result;

}

public function fetchAssoc($resource){

$rowList = array();

while($row = mysqli_fetch_assoc($resource)){

$rowList[] = $row;

}

return $rowList;

}

public function select($sql){

$result = $this->query($sql);

$rowList = $this->fetchAssoc($result);

return $rowList;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值