chengkun
2025-04-29 ab5d7bddae4557b9d56d17f21fc8ca232d7d8693
app/public/action.class.php
@@ -1,7 +1,6 @@
<?php
class model {
    // 操作状态
    const MODEL_INSERT = 1;      //  插入模型数据
@@ -152,33 +151,41 @@
    protected function _initialize() {
    }
    
    function insert_into($table, $data = array()) {
    function get_table_fields($tableName): array {
        include(CONFIG_PATH . 'db.config.php');
        $mysqli = new mysqli($db_config['dbhost'], $db_config['dbuser'], $db_config['dbpass'], $db_config['dbname']);
        $query = $mysqli->query("SHOW COLUMNS FROM $tableName");
        $tableFields = array();
        while ($row = $query->fetch_assoc()) {
            $tableFields[] = $row['Field'];
        }
        return $tableFields;
    }
        
        
    function insert_into($table, $data = array()): bool {
        $value = array();
        $this->db->connect();
        include(PLUS_PATH . 'dbstruct.cache.php');
        $TableFullName = $this->def . $table;
        if (is_array($$TableFullName)) {
            $fields = array_keys($$TableFullName);
        } else {
        $fields = $this->get_table_fields($TableFullName);
        if (!$fields) {
            return FALSE;
        }
        if (is_array($fields)) {
            if (is_array($data)) {
        if (!is_array($data)) {
            return FALSE;
        }
                foreach ($data as $key => $v) {
                    if (in_array($key, $fields)) {
                        $v = $this->FilterStr($v);
                        $value[] = "`" . $key . "`='" . $this->db->escape_string($v) . "'";
                    }
                }
            }
        }
        $value = @implode(",", $value);
        if (!$value) {
            return FALSE;
        }
        return $this->DB_insert_once($table, $value);
    }
    
@@ -187,7 +194,15 @@
        $this->db->connect();
        $value = array();
        include(PLUS_PATH . 'dbstruct.cache.php');
//        $TableFullName=$this->def.$table;
        $TableFullName = $this->def . $table;
        $fields = $this->get_table_fields($TableFullName);
        if (!is_array($data) || !is_array($where)) {
            return FALSE;
        }
        if (!$fields) {
            return FALSE;
        }
//        var_dump($$TableFullName);exit();
//        if (is_array($where)) {
//            $fields = array_keys($where);
@@ -197,10 +212,10 @@
//        var_dump($fields);exit();
        
        
        if (is_array($data)) {
            foreach ($data as $key => $v) {
            if (!in_array($key, $fields)) {
                continue;
            }
                if (is_array($v)) {
                    
                    if ($v[0] == '+') {
@@ -247,7 +262,6 @@
                    $value[] = "`" . $key . "`='" . $this->db->escape_string($v) . "'";
                }
                
            }
        }
        
        
@@ -543,6 +557,13 @@
        }
        include(PLUS_PATH . 'dbstruct.cache.php');
        $TableFullName = $this->def . $tablename;
        /////获取表的字段
        if (!isset($$TableFullName)) {
            $this->error = '表结构缓存文件不存在';
            return FALSE;
        }
        if (is_array($$TableFullName)) {
            $fieldsArr = array_keys($$TableFullName);
        }