| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
database.c - description |
database.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 11 2004 |
begin : Mon Oct 11 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 6 |
email : leaflet@leafok.com |
email : leaflet@leafok.com |
| 7 |
***************************************************************************/ |
***************************************************************************/ |
| 8 |
|
|
| 9 |
/*************************************************************************** |
/*************************************************************************** |
| 20 |
#include <stdio.h> |
#include <stdio.h> |
| 21 |
|
|
| 22 |
MYSQL * |
MYSQL * |
| 23 |
db_open () |
db_open() |
| 24 |
{ |
{ |
| 25 |
MYSQL *db; |
MYSQL *db; |
| 26 |
|
char sql[1024]; |
| 27 |
|
|
| 28 |
db = mysql_init (NULL); |
db = mysql_init(NULL); |
| 29 |
if (db == NULL) |
if (db == NULL) |
| 30 |
{ |
{ |
| 31 |
log_error ("mysql_init() failed\n"); |
log_error("mysql_init() failed\n"); |
| 32 |
return NULL; |
return NULL; |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
db = mysql_real_connect (db, DB_host, DB_username, DB_password, DB_database, |
db = mysql_real_connect(db, DB_host, DB_username, DB_password, DB_database, |
| 36 |
0, NULL, 0); |
0, NULL, 0); |
| 37 |
if (db == NULL) |
if (db == NULL) |
| 38 |
{ |
{ |
| 39 |
log_error ("mysql_connect() failed\n"); |
log_error("mysql_connect() failed\n"); |
| 40 |
return NULL; |
return NULL; |
| 41 |
} |
} |
| 42 |
|
|
| 43 |
|
if (mysql_set_character_set(db, "gb2312") != 0) |
| 44 |
|
{ |
| 45 |
|
log_error("Set character set failed\n"); |
| 46 |
|
return NULL; |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
sprintf(sql, |
| 50 |
|
"SET time_zone = '%s'", |
| 51 |
|
DB_timezone); |
| 52 |
|
|
| 53 |
|
if (mysql_query(db, sql) != 0) |
| 54 |
|
{ |
| 55 |
|
log_error("Set timezone failed\n"); |
| 56 |
|
return NULL; |
| 57 |
|
} |
| 58 |
|
|
| 59 |
return db; |
return db; |
| 60 |
} |
} |