Kylix Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
카일릭스 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
자유게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

카일릭스 Q&A
[265] Re:리눅스에서 c로 플그램 하나 짜려고 하는데요...c로 mysql 연동할수 있는지요,....
il's [magicfox] 3508 읽음    2003-08-25 11:41
#include <mysql.h>

#define  hostip "localhost"
#define  dbname "TEST"

#define user "TEST"
#define passwd "TEST"

MYSQL        mysql, *connection;
MYSQL_ROW     row;
MYSQL_RES    *result;

int main(int argc,char *argv[])
{
    int RecordCount;
    char *TableName;

    mysql_init(&mysql);   
    connection = mysql_real_connect(&mysql, hostip, user, passwd, dbname, 0, "/tmp/mysql.sock", 0);
   
    if(connection == NULL)
    {
        printf("%s\n",mysql_error(&mysql));   //데이터베이스 연결에러
        exit(1);
    }
   
    strcpy(query,"SELECT * FROM %s", TableName);
   
    if (mysql_query(connection, query))
    {
        printf(mysql_error(connection));
        exit(1);   
    }   
    result = mysql_store_result(connection);
   
    RecordCount = mysql_num_rows(result);

    if (RecordCount != 0)
    {
    for (i = 0; i < RecordCount; i++)
    {       
           row = mysql_fetch_row(result);
             printf("Field 0 : %s \n", row[0]);
             printf("Field 1 : %s \n", row[1]);
             printf("Field 2 : %s \n", row[2]);
             printf("Field 3 : %s \n", row[3]);
         }
    }
    mysql_free_result(result);      
    mysql_close(connection);
    return 0;
}

이렇게 하시면 될겁니다....
그리고 참고로 컴파일 할때..

gcc -o aaa.out aaa.c -lmysqlclient
이렇게 라이브러리 링크해주셔야 합니다.




rkd 님이 쓰신 글 :
: 왜 php로 mysql연동해서 짜잖아요....뭐 select name from aa; 뭐이런식으로 질의어 보내서
: c 언어로   db 검색할수 있나요.....그래서 뿌려주고...그렇게요 방법이 있을까요?

+ -

관련 글 리스트
264 리눅스에서 c로 플그램 하나 짜려고 하는데요...c로 mysql 연동할수 있는지요,.... rkd 2619 2003/08/18
265     Re:리눅스에서 c로 플그램 하나 짜려고 하는데요...c로 mysql 연동할수 있는지요,.... il's 3508 2003/08/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.