--- lbbs/src/database.c 2025/04/28 03:30:59 1.7 +++ lbbs/src/database.c 2025/06/03 05:33:06 1.15 @@ -1,28 +1,36 @@ /*************************************************************************** database.c - description ------------------- - begin : Mon Oct 11 2004 - copyright : (C) 2004 by Leaflet - email : leaflet@leafok.com + Copyright : (C) 2004-2025 by Leaflet + Email : leaflet@leafok.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * + * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "common.h" -#include +#include "database.h" +#include "log.h" #include +#include -MYSQL * -db_open() +// Global declaration for database +char DB_host[256]; +char DB_username[50]; +char DB_password[50]; +char DB_database[50]; +char DB_timezone[50]; + +MYSQL *db_open() { MYSQL *db; + char sql[SQL_BUFFER_LEN]; db = mysql_init(NULL); if (db == NULL) @@ -39,15 +47,19 @@ db_open() return NULL; } - if (mysql_query(db, "SET CHARACTER SET gb2312") != 0) + if (mysql_set_character_set(db, "gb2312") != 0) { - log_error("SET CHARACTER SET failed\n"); + log_error("Set character set failed\n"); return NULL; } - if (mysql_query(db, "SET NAMES \'gb2312\'") != 0) + snprintf(sql, sizeof(sql), + "SET time_zone = '%s'", + DB_timezone); + + if (mysql_query(db, sql) != 0) { - log_error("SET NAMES failed\n"); + log_error("Set timezone error: %s\n", mysql_error(db)); return NULL; }