/[LeafOK_CVS]/lbbs/src/database.c
ViewVC logotype

Diff of /lbbs/src/database.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 by sysadm, Tue Oct 19 17:11:28 2004 UTC Revision 1.18 by sysadm, Tue Nov 4 13:49:51 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                           database.c  -  description  /*
3                               -------------------   * database
4      begin                : Mon Oct 11 2004   *   - configuration and function of DB connection
5      copyright            : (C) 2004 by Leaflet   *
6      email                : leaflet@leafok.com   * Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com>
7   ***************************************************************************/   */
   
 /***************************************************************************  
  *                                                                         *  
  *   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     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
 #include "bbs.h"  
9  #include "common.h"  #include "common.h"
10    #include "database.h"
11    #include "log.h"
12    #include <stdio.h>
13    #include <mysql/mysql.h>
14    
15  MYSQL *  // Global declaration for database
16  db_open ()  char DB_host[256];
17    char DB_username[50];
18    char DB_password[50];
19    char DB_database[50];
20    char DB_timezone[50];
21    
22    MYSQL *db_open()
23  {  {
24            MYSQL *db = NULL;
25            char sql[SQL_BUFFER_LEN];
26    
27            db = mysql_init(NULL);
28            if (db == NULL)
29            {
30                    log_error("mysql_init() failed\n");
31                    return NULL;
32            }
33    
34            if (mysql_real_connect(db, DB_host, DB_username, DB_password, DB_database,
35                                                       0, NULL, 0) == NULL)
36            {
37                    log_error("mysql_real_connect() error: %s\n", mysql_error(db));
38                    mysql_close(db);
39                    return NULL;
40            }
41    
42            if (mysql_set_character_set(db, "utf8") != 0)
43            {
44                    log_error("Set character set error: %s\n", mysql_error(db));
45                    mysql_close(db);
46                    return NULL;
47            }
48    
49            snprintf(sql, sizeof(sql),
50                             "SET time_zone = '%s'",
51                             DB_timezone);
52    
53            if (mysql_query(db, sql) != 0)
54            {
55                    log_error("Set timezone error: %s\n", mysql_error(db));
56                    mysql_close(db);
57                    return NULL;
58            }
59    
60            return db;
61  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1