整合資料庫、完成登入註冊忘記密碼功能
This commit is contained in:
54
scripts/test-db-connection.js
Normal file
54
scripts/test-db-connection.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
async function testDbConnection() {
|
||||
console.log('🧪 測試資料庫連接...\n');
|
||||
|
||||
try {
|
||||
// 資料庫配置
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'mysql.theaken.com',
|
||||
port: parseInt(process.env.DB_PORT || '33306'),
|
||||
user: process.env.DB_USER || 'AI_Platform',
|
||||
password: process.env.DB_PASSWORD || 'Aa123456',
|
||||
database: process.env.DB_NAME || 'db_AI_Platform',
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00'
|
||||
};
|
||||
|
||||
console.log('連接配置:', {
|
||||
host: dbConfig.host,
|
||||
port: dbConfig.port,
|
||||
user: dbConfig.user,
|
||||
database: dbConfig.database
|
||||
});
|
||||
|
||||
// 創建連接
|
||||
const connection = await mysql.createConnection(dbConfig);
|
||||
console.log('✅ 資料庫連接成功');
|
||||
|
||||
// 測試查詢
|
||||
const [rows] = await connection.execute('SELECT COUNT(*) as count FROM users WHERE is_active = TRUE');
|
||||
console.log('✅ 查詢成功,用戶數量:', rows[0].count);
|
||||
|
||||
// 測試用戶列表查詢
|
||||
const [users] = await connection.execute(`
|
||||
SELECT
|
||||
id, name, email, avatar, department, role, join_date,
|
||||
total_likes, total_views, is_active, last_login, created_at, updated_at
|
||||
FROM users
|
||||
WHERE is_active = TRUE
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 10
|
||||
`);
|
||||
console.log('✅ 用戶列表查詢成功,返回用戶數:', users.length);
|
||||
|
||||
await connection.end();
|
||||
console.log('✅ 連接已關閉');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 資料庫連接失敗:', error.message);
|
||||
console.error('詳細錯誤:', error);
|
||||
}
|
||||
}
|
||||
|
||||
testDbConnection();
|
Reference in New Issue
Block a user