setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec("SET NAMES utf8"); echo "数据库连接成功!
"; } catch (PDOException $e) { die("数据库连接失败: " . $e->getMessage()); } // 确保表存在 try { $sql = "CREATE TABLE IF NOT EXISTS task ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(100) NOT NULL, tool_name VARCHAR(100) NOT NULL, task_name VARCHAR(100) NOT NULL, time_saved VARCHAR(100) NOT NULL, time_cost VARCHAR(100) NOT NULL, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP )"; $pdo->exec($sql); echo "表结构检查完成!
"; } catch (PDOException $e) { die("创建表失败: " . $e->getMessage()); } // 清空现有数据(可选) try { $pdo->exec("TRUNCATE TABLE task"); echo "表已清空,准备插入测试数据...
"; } catch (PDOException $e) { echo "清空表失败: " . $e->getMessage() . "
"; } // 准备测试数据 $test_data = [ [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox', 'task_name' => 'CheckUV', 'time_saved' => '5.2', 'time_cost' => '0.3', 'timestamp' => '2025-04-01 09:30:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox', 'task_name' => 'FixNormals', 'time_saved' => '3.5', 'time_cost' => '0.2', 'timestamp' => '2025-04-01 10:15:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'RigTools', 'task_name' => 'AutoRig', 'time_saved' => '12.0', 'time_cost' => '1.5', 'timestamp' => '2025-04-02 14:20:00' ], [ 'username' => 'LiuYang', 'tool_name' => 'TextureManager', 'task_name' => 'BatchExport', 'time_saved' => '8.5', 'time_cost' => '0.8', 'timestamp' => '2025-04-03 11:45:00' ], [ 'username' => 'LiuYang', 'tool_name' => 'TextureManager', 'task_name' => 'ResizeTextures', 'time_saved' => '4.2', 'time_cost' => '0.5', 'timestamp' => '2025-04-03 15:30:00' ], [ 'username' => 'ZhangWei', 'tool_name' => 'AnimTools', 'task_name' => 'CycleCheck', 'time_saved' => '6.8', 'time_cost' => '0.4', 'timestamp' => '2025-04-04 09:15:00' ], [ 'username' => 'ZhangWei', 'tool_name' => 'AnimTools', 'task_name' => 'KeyCleaner', 'time_saved' => '5.5', 'time_cost' => '0.3', 'timestamp' => '2025-04-04 14:45:00' ], [ 'username' => 'WangFang', 'tool_name' => 'LightingSetup', 'task_name' => 'HDRIManager', 'time_saved' => '7.2', 'time_cost' => '0.6', 'timestamp' => '2025-04-05 10:30:00' ], [ 'username' => 'WangFang', 'tool_name' => 'LightingSetup', 'task_name' => 'ShadowFix', 'time_saved' => '3.8', 'time_cost' => '0.4', 'timestamp' => '2025-04-05 16:20:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox', 'task_name' => 'CheckUV', 'time_saved' => '5.0', 'time_cost' => '0.3', 'timestamp' => '2025-04-06 11:10:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox(Debug)', 'task_name' => 'TestFeature', 'time_saved' => '0.5', 'time_cost' => '1.2', 'timestamp' => '2025-04-07 09:45:00' ], [ 'username' => 'LiuYang', 'tool_name' => 'TextureManager', 'task_name' => 'BatchExport', 'time_saved' => '8.0', 'time_cost' => '0.7', 'timestamp' => '2025-04-08 13:30:00' ], [ 'username' => 'ZhangWei', 'tool_name' => 'AnimTools', 'task_name' => 'CycleCheck', 'time_saved' => '6.5', 'time_cost' => '0.4', 'timestamp' => '2025-04-09 10:20:00' ], [ 'username' => 'WangFang', 'tool_name' => 'LightingSetup', 'task_name' => 'HDRIManager', 'time_saved' => '7.0', 'time_cost' => '0.6', 'timestamp' => '2025-04-10 15:45:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'RigTools', 'task_name' => 'AutoRig', 'time_saved' => '11.5', 'time_cost' => '1.4', 'timestamp' => '2025-04-11 09:30:00' ], [ 'username' => 'LiuYang', 'tool_name' => 'TextureManager', 'task_name' => 'ResizeTextures', 'time_saved' => '4.0', 'time_cost' => '0.5', 'timestamp' => '2025-04-12 14:15:00' ], [ 'username' => 'ZhangWei', 'tool_name' => 'AnimTools', 'task_name' => 'KeyCleaner', 'time_saved' => '5.2', 'time_cost' => '0.3', 'timestamp' => '2025-04-12 16:40:00' ], [ 'username' => 'WangFang', 'tool_name' => 'LightingSetup', 'task_name' => 'ShadowFix', 'time_saved' => '3.5', 'time_cost' => '0.4', 'timestamp' => '2025-04-13 10:15:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox', 'task_name' => 'FixNormals', 'time_saved' => '3.2', 'time_cost' => '0.2', 'timestamp' => '2025-04-13 11:30:00' ], [ 'username' => 'JeffreyTsai', 'tool_name' => 'MetaBox', 'task_name' => 'CheckUV', 'time_saved' => '5.1', 'time_cost' => '0.3', 'timestamp' => '2025-04-13 13:45:00' ] ]; // 插入测试数据 $success_count = 0; $stmt = $pdo->prepare("INSERT INTO task (username, tool_name, task_name, time_saved, time_cost, timestamp) VALUES (:username, :tool_name, :task_name, :time_saved, :time_cost, :timestamp)"); foreach ($test_data as $data) { try { $stmt->bindParam(':username', $data['username']); $stmt->bindParam(':tool_name', $data['tool_name']); $stmt->bindParam(':task_name', $data['task_name']); $stmt->bindParam(':time_saved', $data['time_saved']); $stmt->bindParam(':time_cost', $data['time_cost']); $stmt->bindParam(':timestamp', $data['timestamp']); $stmt->execute(); $success_count++; } catch (PDOException $e) { echo "插入数据失败: " . $e->getMessage() . "
"; } } echo "成功插入 {$success_count} 条测试数据!
"; echo "
所有操作已完成!
"; echo "返回首页 | 查看数据"; ?>