no commit message

This commit is contained in:
雨中磐石
2024-10-18 15:27:40 +08:00
parent 9a2a3a2c8a
commit 559c388ea0
103 changed files with 2021 additions and 783 deletions

View File

@@ -72,8 +72,8 @@ abstract class mysql{
$this->tranend();
$this->close();
}
//记录访问sql日志
if(getconfig('sqllog')){
//记录访问sql日志(2024-10-13弃用)
if(getconfig('sqllog') && 1==2){
$sql = '';
$filstr = 'sqllog_'.date('Y.m.d.H.i.s').'_'.$this->rock->adminid.'_'.str_shuffle('abcdefghijklmn').'.log';
foreach($this->sqlarr as $sql1)$sql.="\n\n$sql1;";
@@ -95,7 +95,7 @@ abstract class mysql{
public function fetch_array($res, $type=0){return false;}
public function insert_id(){return 0;}
public function error(){return '';}
public function error(){return $this->errorlast;}
public function close(){}
@@ -127,13 +127,8 @@ abstract class mysql{
$this->sqlarr[] = $sql;
$this->nowsql = $sql;
$this->count = 0;
try {
$rsbool = $this->querysql($sql);
} catch (Exception $e) {
$rsbool = false;
$this->errormsg = $e->getMessage();
}
$rsbool = $this->querysql($sql);
$this->nowerror = false;
if(!$rsbool)$this->nowerror = true;
@@ -142,7 +137,7 @@ abstract class mysql{
//记录错误sql
if(!$rsbool && $ebo){
$txt = '[ERROR SQL]'.chr(10).''.$sql.''.chr(10).''.chr(10).'[Reason]'.chr(10).''.$this->error().''.chr(10).'';
$txt = '[ERROR SQL]'.chr(10).$sql.chr(10).chr(10).''.$this->getError().''.chr(10).'';
$efile = $this->rock->debug($txt,''.DB_DRIVE.'_sqlerr', true);
$errmsg = str_replace("'",''', $this->error());
if(!contain($sql, $stabs)){
@@ -154,6 +149,30 @@ abstract class mysql{
return $rsbool;
}
public $isError = false;
private $msgerror = '';
private $msgerrorall = '';
/**
* 设置错误信息
*/
public function setError($str, $sql){
if(!$str)return;
$this->isError = true;
$this->errorlast = $str;
$this->errormsg = $str;
$this->msgerror .= ''.$str.';';
$this->msgerrorall .= ''.$sql.chr(10).chr(10).$str.chr(10).chr(10).'';
}
/**
* 获取错误
*/
public function getError()
{
return $this->msgerrorall;
}
/**
* 返回最后错误信息
*/
@@ -260,12 +279,13 @@ abstract class mysql{
return $this->getall($sql);
}
public function getall($sql)
public function getall($sql, $call=null)
{
$res=$this->query($sql);
$arr=array();
if($res){
while($row=$this->fetch_array($res)){
if($call != null)$row = $call($row);
$arr[] = $row;
$this->count++;
}
@@ -593,15 +613,14 @@ abstract class mysql{
}
/**
返回表所有字段
* 返回表所有字段,如['id','name']
*/
public function getallfields($table)
{
$finfo = $this->gettablefields($table);
foreach ($finfo as $val) {
$arr[] = $val['name'];
}
return $arr;
$sql = 'SHOW FULL COLUMNS FROM `'.$table.'`';
return $this->getall($sql, function($row){
return $row['Field'];
});
}
public function getfields($table)
@@ -614,7 +633,9 @@ abstract class mysql{
public function gettablefields($table, $base='',$whe='')
{
if($base=='')$base = $this->db_base;
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,`COLUMN_DEFAULT` as dev,`IS_NULLABLE` as isnull,`CHARACTER_MAXIMUM_LENGTH` as lens,`NUMERIC_PRECISION` as xslen1,`NUMERIC_SCALE` as xslen2 from information_schema.COLUMNS where `TABLE_NAME`='$table' and `TABLE_SCHEMA` ='$base' $whe order by `ORDINAL_POSITION`";
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,`COLUMN_DEFAULT` as dev,`IS_NULLABLE` as isnull,`CHARACTER_MAXIMUM_LENGTH` as lens,`NUMERIC_PRECISION` as xslen1,`NUMERIC_SCALE` as xslen2 from information_schema.COLUMNS where `TABLE_SCHEMA` ='$base' AND `TABLE_NAME`='$table' $whe order by `ORDINAL_POSITION`";
//SHOW FULL COLUMNS FROM table_name
return $this->getall($sql);
}

View File

@@ -19,7 +19,9 @@ class mysqliClass extends mysql{
protected function querysql($sql)
{
return $this->conn->query($sql);
$roboll = $this->conn->query($sql);
if(!$roboll)$this->setError($this->conn->error, $sql);
return $roboll;
}
public function fetch_array($result, $type = 0)
@@ -58,11 +60,7 @@ class mysqliClass extends mysql{
}
return $arr;
}
public function error()
{
return 'mysqliError:'.$this->conn->error;
}
public function close()
{

View File

@@ -11,6 +11,7 @@ class pdoClass extends mysql{
$this->conn = @new PDO('mysql:host='.$this->db_host.';dbname='.$this->db_base.'', $this->db_user, $this->db_pass);
$this->conn->query("SET NAMES 'utf8'");
$this->selectdb($this->db_base);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
$this->conn = null;
$this->errormsg = $e->getMessage();
@@ -23,7 +24,7 @@ class pdoClass extends mysql{
$bo = $this->conn->query($sql);
} catch (PDOException $e) {
$bo = false;
$this->errormsg = $e->getMessage();
$this->setError($e->getMessage(), $sql);
}
return $bo;
}
@@ -53,11 +54,7 @@ class pdoClass extends mysql{
}
}
public function error()
{
$str = $this->conn->errorInfo();
return 'pdoError('.$str[0].'):'.$str[2].''.$this->errormsg.'';
}
public function close()
{

View File

@@ -84,6 +84,11 @@ final class rockClass
$this->adminid = (int)$this->session('adminid',0);
$this->adminname= $this->session('adminname');
$this->adminuser= $this->session('adminuser');
$apptheme = $this->get('apptheme');
if(strlen($apptheme)==6)$this->savecookie('apptheme', $apptheme);
if(!$apptheme)$apptheme = $this->cookie('apptheme');
if(strlen($apptheme)==6)$GLOBALS['config']['apptheme']='#'.$apptheme.'';
}
public function iconvsql($str,$lx=0)
@@ -251,7 +256,7 @@ final class rockClass
$valn = $valarr;
if(!is_array($valarr))$valn=explode(',',$valarr);
for($i=0;$i<count($arrn);$i++){
setcookie(QOM.$arrn[$i],$valn[$i], $time, $path,'');
@setcookie(QOM.$arrn[$i],$valn[$i], $time, $path,'');
}
}