diff --git a/library/think/db/driver.php b/library/think/db/driver.php index 0005674c..6abb9204 100644 --- a/library/think/db/driver.php +++ b/library/think/db/driver.php @@ -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; } diff --git a/library/think/model.php b/library/think/model.php index f1635a0b..70c5272a 100644 --- a/library/think/model.php +++ b/library/think/model.php @@ -1317,4 +1317,14 @@ class Model { } return $this; } + + /** + * 设置从主服务器读取数据 + * @access public + * @return Model + */ + public function readMaster(){ + $this->options['read_master'] = true; + return $this; + } } \ No newline at end of file