Files
zyt/server/install_tracking_tables.php
2026-04-07 18:13:03 +08:00

71 lines
1.8 KiB
PHP

<?php
/**
* 安装物流追踪表
*/
// 数据库配置
$host = '39.97.232.35';
$port = '3306';
$database = 'cs_zyt';
$username = 'root';
$password = '749b460091647766';
$charset = 'utf8mb4';
// 连接数据库
$dsn = "mysql:host={$host};port={$port};charset={$charset}";
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// 选择数据库
$pdo->exec("USE `{$database}`");
echo "开始创建物流追踪表...\n\n";
// 读取SQL文件
$sql = file_get_contents(__DIR__ . '/database/migrations/create_express_tracking_tables.sql');
// 分割SQL语句
$statements = array_filter(
array_map('trim', explode(';', $sql)),
function($stmt) {
return !empty($stmt) &&
!preg_match('/^--/', $stmt) &&
!preg_match('/^\/\*/', $stmt);
}
);
$success = 0;
$failed = 0;
foreach ($statements as $statement) {
try {
$pdo->exec($statement);
// 提取表名
if (preg_match('/CREATE TABLE.*?`(\w+)`/i', $statement, $matches)) {
echo "✓ 创建表: {$matches[1]}\n";
$success++;
}
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'already exists') !== false) {
if (preg_match('/CREATE TABLE.*?`(\w+)`/i', $statement, $matches)) {
echo "- 表已存在: {$matches[1]}\n";
}
} else {
echo "✗ 错误: {$e->getMessage()}\n";
$failed++;
}
}
}
echo "\n========================================\n";
echo "安装完成!\n";
echo "========================================\n";
echo "成功: {$success}\n";
echo "失败: {$failed}\n";
echo "\n";
echo "下一步:\n";
echo " php think express:sync # 同步现有快递单号\n";
echo " php think express:auto-update # 测试自动更新\n";
echo "\n";