source: ogServer-Git/sources/dbi.c @ c46fa3c

Last change on this file since c46fa3c was ad2d308, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#967 rename .cpp to .c

This actually is C code, use the gcc compiler instead.

  • Property mode set to 100644
File size: 807 bytes
RevLine 
[2629906]1#include "dbi.h"
2
3struct og_dbi *og_dbi_open(struct og_dbi_config *config)
4{
5        struct og_dbi *dbi;
6
7        dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi));
8        if (!dbi)
9                return NULL;
10
11        dbi_initialize_r(NULL, &dbi->inst);
12        dbi->conn = dbi_conn_new_r("mysql", dbi->inst);
13        if (!dbi->conn) {
14                free(dbi);
15                return NULL;
16        }
17
18        dbi_conn_set_option(dbi->conn, "host", config->host);
19        dbi_conn_set_option(dbi->conn, "username", config->user);
20        dbi_conn_set_option(dbi->conn, "password", config->passwd);
21        dbi_conn_set_option(dbi->conn, "dbname", config->database);
22        dbi_conn_set_option(dbi->conn, "encoding", "UTF-8");
23
24        if (dbi_conn_connect(dbi->conn) < 0) {
25                free(dbi);
26                return NULL;
27        }
28
29        return dbi;
30}
31
32void og_dbi_close(struct og_dbi *dbi)
33{
34        dbi_conn_close(dbi->conn);
35        dbi_shutdown_r(dbi->inst);
36        free(dbi);
37}
Note: See TracBrowser for help on using the repository browser.