mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
设置了主从服务器后,支持从主服务器读数据
方法是在模型类中调用 readMaster方法 $this->readMaster()->select(); 该方法当此调用有效
This commit is contained in:
@@ -130,10 +130,11 @@ abstract class Driver {
|
||||
* @access public
|
||||
* @param string $str sql指令
|
||||
* @param boolean $fetchSql 不执行只是获取SQL
|
||||
* @param boolean $master 是否在主服务器读操作
|
||||
* @return mixed
|
||||
*/
|
||||
public function query($str,$fetchSql=false) {
|
||||
$this->initConnect(false);
|
||||
public function query($str,$fetchSql=false,$master=false) {
|
||||
$this->initConnect($master);
|
||||
if ( !$this->_linkID ) return false;
|
||||
$this->queryStr = $str;
|
||||
if(!empty($this->bind)){
|
||||
@@ -935,7 +936,7 @@ abstract class Driver {
|
||||
$this->model = $options['model'];
|
||||
$this->parseBind(!empty($options['bind'])?$options['bind']:array());
|
||||
$sql = $this->buildSelectSql($options);
|
||||
$result = $this->query($sql,!empty($options['fetch_sql']) ? true : false);
|
||||
$result = $this->query($sql,!empty($options['fetch_sql']) ? true : false,!empty($options['read_master']) ? true : false);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1317,4 +1317,14 @@ class Model {
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置从主服务器读取数据
|
||||
* @access public
|
||||
* @return Model
|
||||
*/
|
||||
public function readMaster(){
|
||||
$this->options['read_master'] = true;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user