--- lbbs/src/database.c 2025/04/28 12:45:57 1.8 +++ lbbs/src/database.c 2025/06/03 05:33:06 1.15 @@ -1,29 +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[1024]; + char sql[SQL_BUFFER_LEN]; db = mysql_init(NULL); if (db == NULL) @@ -46,13 +53,13 @@ db_open() return NULL; } - sprintf(sql, - "SET time_zone = '%s'", - DB_timezone); + snprintf(sql, sizeof(sql), + "SET time_zone = '%s'", + DB_timezone); if (mysql_query(db, sql) != 0) { - log_error("Set timezone failed\n"); + log_error("Set timezone error: %s\n", mysql_error(db)); return NULL; }