'empty', 'key_name' => 'sql', 'error_msg' => '执行SQL不能为空', ] ]; $ret = ParamsChecked($params, $p); if($ret !== true) { return DataReturn($ret, -1); } // 表前缀,编码替换 $config = MyConfig('database.connections.mysql'); $sql = str_replace('{PREFIX}', $config['prefix'], $params['sql']); $sql = str_replace('{CHARSET}', $config['charset'], $sql); // 转为数组 $sql_all = preg_split("/;[\r\n]+/", $sql); $success = 0; $failure = 0; foreach($sql_all as $v) { if (!empty($v)) { if(Db::execute($v) !== false) { $success++; } else { $failure++; } } } if($failure > 0) { return DataReturn('sql运行失败['.$failure.']条', -1); } return DataReturn('sql运行成功', 0, 'sql运行成功[success: '.$success.', failure: '.$failure.']'); } } ?>