diff --git a/bin/ztcli b/bin/ztcli index bba04dedb2..d6f4fd96ad 100755 --- a/bin/ztcli +++ b/bin/ztcli @@ -56,12 +56,12 @@ if($config->requestType == 'PATH_INFO') else { parse_str($request['query'], $_GET); - $_SERVER['SCRIPT_NAME'] = $_SERVER['HTTP_HOST'] . 'index.php'; + $_SERVER['SCRIPT_NAME'] = $request['path']; $_SERVER['REQUEST_URI'] = isset($request['query']) ? $request['query'] : ''; } /* Instance the app and run it. */ -$app = router::createApp('pms', dirname(dirname(__FILE__))); +$app = router::createApp('pms', dirname(dirname(__FILE__)), 'router'); $common = $app->loadCommon(); $app->parseRequest(); $app->loadModule(); diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index 0fa13eeffc..ec94bb3fd0 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -684,18 +684,18 @@ class baseDAO if($this->slaveDBH and $method == 'select') { - if(isset(dao::$cache[$key])) return dao::$cache[$key]; + if(isset(dao::$cache['query'][$key])) return dao::$cache['query'][$key]; $result = $this->slaveDBH->query($sql); - dao::$cache[$key] = $result; + dao::$cache['query'][$key] = $result; return $result; } else { if($this->method == 'select') { - if(isset(dao::$cache[$key])) return dao::$cache[$key]; + if(isset(dao::$cache['query'][$key])) return dao::$cache['query'][$key]; $result = $this->slaveDBH->query($sql); - dao::$cache[$key] = $result; + dao::$cache['query'][$key] = $result; return $result; } @@ -773,10 +773,23 @@ class baseDAO */ public function fetch($field = '') { - if(empty($field)) return $this->query()->fetch(); + $sql = $this->processSQL(); + $key = md5($sql); + if(isset(dao::$cache['fetch'][$key][$field])) return dao::$cache['fetch'][$key][$field]; + + if(empty($field)) + { + $result = $this->query()->fetch(); + dao::$cache['fetch'][$key][$field] = $result; + return $result; + } $this->setFields($field); $result = $this->query()->fetch(PDO::FETCH_OBJ); - if($result) return $result->$field; + if($result) + { + dao::$cache['fetch'][$key][$field] = $result->$field; + return $result->$field; + } } /** @@ -790,10 +803,20 @@ class baseDAO */ public function fetchAll($keyField = '') { + $sql = $this->processSQL(); + $key = md5($sql); + if(isset(dao::$cache['fetchAll'][$key][$keyField])) return dao::$cache['fetchAll'][$key][$keyField]; + $stmt = $this->query(); - if(empty($keyField)) return $stmt->fetchAll(); + if(empty($keyField)) + { + $result = $stmt->fetchAll(); + dao::$cache['fetchAll'][$key][$keyField] = $result; + return $result; + } $rows = array(); while($row = $stmt->fetch()) $rows[$row->$keyField] = $row; + dao::$cache['fetchAll'][$key][$keyField] = $rows; return $rows; } @@ -808,12 +831,17 @@ class baseDAO */ public function fetchGroup($groupField, $keyField = '') { + $sql = $this->processSQL(); + $key = md5($sql); + if(isset(dao::$cache['fetchGroup'][$key][$groupField][$keyField])) return dao::$cache['fetchGroup'][$key][$groupField][$keyField]; + $stmt = $this->query(); $rows = array(); while($row = $stmt->fetch()) { empty($keyField) ? $rows[$row->$groupField][] = $row : $rows[$row->$groupField][$row->$keyField] = $row; } + dao::$cache['fetchGroup'][$key][$groupField][$keyField] = $rows; return $rows; } @@ -834,6 +862,10 @@ class baseDAO $keyField = trim($keyField, '`'); $valueField = trim($valueField, '`'); + $sql = $this->processSQL(); + $key = md5($sql); + if(isset(dao::$cache['fetchPairs'][$key][$keyField][$valueField])) return dao::$cache['fetchPairs'][$key][$keyField][$valueField]; + $pairs = array(); $ready = false; $stmt = $this->query(); @@ -852,6 +884,7 @@ class baseDAO $pairs[$row[$keyField]] = $row[$valueField]; } + dao::$cache['fetchPairs'][$key][$keyField][$valueField] = $pairs; return $pairs; }