|
@@ -104,6 +104,17 @@ trait SQL
|
|
* @var null $table 表名
|
|
* @var null $table 表名
|
|
*/
|
|
*/
|
|
private $table = null;
|
|
private $table = null;
|
|
|
|
+ /**
|
|
|
|
+ * 是否记录SQL
|
|
|
|
+ *
|
|
|
|
+ * @var bool
|
|
|
|
+ */
|
|
|
|
+ private $recordSQL = false;
|
|
|
|
+ /**
|
|
|
|
+ * sql 记录上限
|
|
|
|
+ * @var int
|
|
|
|
+ */
|
|
|
|
+ private $recordLimit = -1;
|
|
/**
|
|
/**
|
|
* 执行的SQL及耗时
|
|
* 执行的SQL及耗时
|
|
*
|
|
*
|
|
@@ -190,6 +201,23 @@ trait SQL
|
|
return '`'.trim($field).'`';
|
|
return '`'.trim($field).'`';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 开始记录SQL语句
|
|
|
|
+ *
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ final public function startRecord(){
|
|
|
|
+ $this->recordSQL = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 记录结束
|
|
|
|
+ *
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ final public function endRecord(){
|
|
|
|
+ $this->recordSQL = false;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* sql执行的开始时间
|
|
* sql执行的开始时间
|
|
*
|
|
*
|
|
@@ -197,10 +225,18 @@ trait SQL
|
|
* @return void
|
|
* @return void
|
|
*/
|
|
*/
|
|
final public function startTime($sql){
|
|
final public function startTime($sql){
|
|
- $this->executionSQL[] = [
|
|
|
|
|
|
+ $record = [
|
|
'sql' => $sql,
|
|
'sql' => $sql,
|
|
'start' => microtime(true)
|
|
'start' => microtime(true)
|
|
];
|
|
];
|
|
|
|
+ if(!$this->recordSQL) {
|
|
|
|
+ $this->executionSQL = [$record];
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if($this->recordLimit > 0 && count($this->executionSQL) >= $this->recordLimit) {
|
|
|
|
+ $this->executionSQL = array_slice($this->executionSQL, 0, $this->recordLimit);
|
|
|
|
+ }
|
|
|
|
+ $this->executionSQL[] = $record;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|