2015년 6월 3일 수요일

MySQL DB connection Sample (2009)

(2009/05/16 00:10 작성)

#define DB_IP "127.0.0.1"
#define DB_USER "root"
#define DB_PASSWD "12345"
#define DB_NAME "mydb"
#define DB_PORT 3306

// DB CONNECT PART ///////////////////////////////////////////////////////////////////////////
void db_disconnect(MYSQL *db)
{
  if (db) mysql_close(db);
}
MYSQL *db_connect(MYSQL *db, char *serverIP)
{
  db = mysql_init(db);
  //fprintf(stderr, "[connect: %s]\n", serverIP);
  if(!mysql_real_connect(db, DB_IP, DB_USER, DB_PASSWD, DB_NAME, DB_PORT, 
      NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS)) {
    db_disconnect(db);
  }
  return (db);
}
// DB CONNECT PART ///////////////////////////////////////////////////////////////////////////

댓글 없음:

댓글 쓰기