|
@@ -138,6 +138,10 @@ class Store
|
|
|
} else {
|
|
|
$this->read = $this->update = $this->connect($this->config);
|
|
|
}
|
|
|
+ # 查询大量数据时,不缓存数据到内存,防止内存溢出
|
|
|
+ if (Dever::config('base')->pdo_no_cache) {
|
|
|
+ $this->read->set();
|
|
|
+ }
|
|
|
$this->config['link'] = false;
|
|
|
}
|
|
|
|
|
@@ -690,7 +694,7 @@ class Store
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
- protected function fetchAll($handle, $config = false)
|
|
|
+ protected function fetchAll($handle, $config = false, $call = false)
|
|
|
{
|
|
|
$rows = function() use ($handle) {
|
|
|
while ($row = $handle->fetch()) {
|
|
@@ -701,35 +705,48 @@ class Store
|
|
|
$data = $rows();
|
|
|
if ($data) {
|
|
|
if ($config) {
|
|
|
- $result = $this->fetchSet($data, $config);
|
|
|
+ $result = $this->fetchSet($data, $config, $call);
|
|
|
} else {
|
|
|
foreach ($data as $row) {
|
|
|
- $result[] = $row;
|
|
|
+ $result[] = $this->cb($call, $row);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * call
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function cb($call, $data)
|
|
|
+ {
|
|
|
+ if ($call) {
|
|
|
+ return $call($data);
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* fetchSet
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
- protected function fetchSet($data, $config)
|
|
|
+ protected function fetchSet($data, $config, $call = false)
|
|
|
{
|
|
|
$result = array();
|
|
|
$key = $config[1];
|
|
|
foreach ($data as $row) {
|
|
|
if (isset($row[$key])) {
|
|
|
if (isset($config[3]) && isset($row[$config[2]])) {
|
|
|
- $result[$row[$key]][$row[$config[2]]] = $row;
|
|
|
+ $result[$row[$key]][$row[$config[2]]] = $this->cb($call, $row);
|
|
|
} elseif (isset($config[2]) && isset($row[$config[2]])) {
|
|
|
- $result[$row[$key]] = $row[$config[2]];
|
|
|
+ $result[$row[$key]] = $this->cb($call, $row[$config[2]]);
|
|
|
} elseif (isset($config[2])) {
|
|
|
- $result[$row[$key]][] = $row;
|
|
|
+ $result[$row[$key]][] = $this->cb($call, $row);
|
|
|
} else {
|
|
|
- $result[$row[$key]] = $row;
|
|
|
+ $result[$row[$key]] = $this->cb($call, $row);
|
|
|
}
|
|
|
}
|
|
|
}
|