Files
work_dhd_back_end/check_db_structure.php
2026-01-06 11:23:52 +08:00

94 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// 查看数据库表结构
require __DIR__ . '/vendor/autoload.php';
// 加载ThinkPHP框架
$app = new think\App();
$app->initialize();
use think\facade\Db;
try {
// 设置数据库配置(从.env读取或直接配置
$dbConfig = [
'default' => 'mysql',
'connections' => [
'mysql' => [
'type' => 'mysql',
'hostname' => '192.168.28.18',
'database' => 'dhd_official_test',
'username' => 'dhd_official_test',
'password' => '4zDsLWZaEzhPAGaf',
'hostport' => '3306',
'charset' => 'utf8',
]
]
];
// 设置配置
\think\facade\Config::set($dbConfig, 'database');
echo "========================================\n";
echo "查看数据库表结构\n";
echo "========================================\n\n";
// 查看职位表结构
echo "【职位表no_notice_position】\n";
echo "----------------------------------------\n";
$positionColumns = Db::query("DESC no_notice_position");
foreach ($positionColumns as $col) {
$field = $col['Field'] ?? $col['field'] ?? '';
$type = $col['Type'] ?? $col['type'] ?? '';
$null = ($col['Null'] ?? $col['null'] ?? '') === 'YES' ? 'NULL' : 'NOT NULL';
echo sprintf("%-30s %-20s %s\n", $field, $type, $null);
}
echo "\n【职位表示例数据前2条\n";
echo "----------------------------------------\n";
$positions = Db::name('no_notice_position')->limit(2)->select()->toArray();
foreach ($positions as $index => $pos) {
echo "记录 " . ($index + 1) . ":\n";
echo "ID: " . ($pos['id'] ?? '') . "\n";
echo "岗位名称: " . ($pos['positon_name'] ?? '') . "\n";
echo "学历要求: " . ($pos['education_require'] ?? '') . "\n";
echo "学位要求: " . ($pos['degree_require'] ?? '') . "\n";
echo "年龄要求: " . ($pos['age_require'] ?? '') . "\n";
echo "性别要求: " . ($pos['sex_require'] ?? '') . "\n";
echo "其他要求(JSON): " . ($pos['position_other_require'] ?? '') . "\n";
echo "\n";
}
echo "\n【用户表t_user】\n";
echo "----------------------------------------\n";
$userColumns = Db::query("DESC t_user");
foreach ($userColumns as $col) {
$field = $col['Field'] ?? $col['field'] ?? '';
$type = $col['Type'] ?? $col['type'] ?? '';
$null = ($col['Null'] ?? $col['null'] ?? '') === 'YES' ? 'NULL' : 'NOT NULL';
echo sprintf("%-30s %-20s %s\n", $field, $type, $null);
}
echo "\n【用户表示例数据前1条\n";
echo "----------------------------------------\n";
$users = Db::name('t_user')->limit(1)->select()->toArray();
if (!empty($users)) {
$user = $users[0];
echo "ID: " . ($user['id'] ?? '') . "\n";
echo "出生日期: " . ($user['birth_date'] ?? '') . "\n";
echo "性别: " . ($user['gender'] ?? '') . "\n";
// 只显示关键字段
$keyFields = ['id', 'birth_date', 'gender', 'education', 'majors_name'];
foreach ($keyFields as $field) {
if (isset($user[$field])) {
echo "$field: " . $user[$field] . "\n";
}
}
}
} catch (\Exception $e) {
echo "错误: " . $e->getMessage() . "\n";
echo "文件: " . $e->getFile() . ":" . $e->getLine() . "\n";
}