database.sarang.net
UserID
Passwd
Database
DBMS
ㆍMySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MySQL Q&A 1374 게시물 읽기
No. 1374
C or C++에서 프로그램 연동하는 법...?
작성자
Sizer
작성일
2000-04-23 03:58
조회수
7,177

저도 지금 학교 프로젝트 나온 것 때문에 C API가 어떻게 되어 있는지

보고 있는데요.. PHP로 코딩해 본 적이 있어서 그런지 그렇게까지 어

렵지는 않은 것 같더군요. (PHP보다는 신경쓸 부분이 많지만요. ^^;;)

 

일단 메뉴얼을 보시면, C API가 어떻게 되어 있는지 자세히(?) 나와

있습니다. C++은 메뉴얼을 보면 두가지 프로젝트가 있다는데, 지금

이상하게 MySQL 웹사이트가 접속이 안 되서 저도 확인은 못 하고 있

습니다. (언제쯤이나 될련지.. --;;)

 

밑의 건 진짜 간단한 예제입니다. 참고가 됐으면 좋겠군요. ^^

DB 테이블 구조는 id하고 name만 있는 거에요.. :)

Output이 어떻게 나오는지는 집적 해 보세요...

(컴파일할 때 워닝이 하나 뜨는데 잘 안 잡히는군요. --;)

 

 

#include <mysql/mysql.h>

#include <stdio.h>

 

int main() {

MYSQL *mysql;

MYSQL_RES *result;

MYSQL_ROW rows;

MYSQL_FIELD *field;

 

char *host = "localhost";

char *db = "test";

char *user = "sizer";

char *password = "";

 

unsigned int num_fields;

unsigned int num_rows;

unsigned int *lengths;

unsigned int i;

 

int ping_status;

 

mysql = mysql_init(NULL);

 

if (!mysql)

printf("Out of Memory

");

else

printf("Success initialize MySQL

");

 

mysql = mysql_connect(mysql, host, user, password);

 

if (mysql)

printf("Success connect MySQL DB Server

");

else

printf("Fail connect MySQL DB Server

");

 

printf("This MySQL Client Version is %s

", mysql_get_client_info());

printf("This MySQL Host is %s

", mysql_get_host_info(mysql));

printf("This MySQL Protocol Version is %u

", mysql_get_proto_info(mysql));

printf("This MySQL Server Version is %s

", mysql_get_server_info(mysql));

 

if (!(mysql_select_db(mysql, db)))

printf("Success change %s Database

", db);

else

printf("Fail change %s Database

", db);

 

if (mysql_query(mysql, "select * from Test")) {

printf("Fail query to %s

", db);

exit(1);

}

else

printf("Success query to %s

", db);

 

result = mysql_store_result(mysql);

 

num_fields = mysql_num_fields(result);

printf("Fields number is %u

", num_fields);

 

num_rows = mysql_affected_rows(mysql);

printf("Rows number is %u

", num_rows);

 

printf("This is Field Structure & Rows of Table Test in test Databases

");

while((field = mysql_fetch_field(result))) {

printf("[%s] ", field->name);

}

printf("

");

 

 

while ((rows = mysql_fetch_row(result))) {

lengths = mysql_fetch_lengths(result);

 

for (i = 0; i < num_fields; i++) {

printf("[%.*s] ", (int)lengths, rows ? rows : "NULL");

}

printf("

");

}

 

mysql_free_result(result);

printf("Query results is freed

");

 

if (!(ping_status = mysql_ping(mysql)))

printf("Ping Result: Server is connected

");

else

printf("Ping Result: Server is not connected

");

 

mysql_close(mysql);

printf("Teminate Server connect

");

 

if (!(ping_status = mysql_ping(mysql)))

printf("Ping Result: Server is connected

");

else

printf("Ping Result: Server is not connected

");

 

return 0;

}

[Top]
No.
제목
작성자
작성일
조회
1380# [질문] oracle 의 to_number 같은 기능이 있나요 ? [1]
도와줘
2000-04-24
7029
1392┕>Re: # [질문] oracle 의 to_number 같은 기능이 있나요 ?
정재익
2000-04-25 07:28:43
7621
1376[질문] 테이블을 옮기기...
하늘보기
2000-04-24
6492
1377┕>Re: [질문] 테이블을 옮기기...
정재익
2000-04-24 06:51:35
6620
1375mysql로 구성한 db를 델파이에서 접근하기
왕초보
2000-04-23
6355
1378┕>Re: mysql로 구성한 db를 델파이에서 접근하기
정재익
2000-04-24 06:56:33
6700
1383┕># Re: mysql로 구성한 db를 델파이에서 접근하기
강석채
2000-04-24 19:43:42
6584
1372C or C++에서 mysql 연동하는법..(긴급....)
u96yhs
2000-04-22
6476
1374┕>C or C++에서 프로그램 연동하는 법...?
Sizer
2000-04-23 03:58:50
7177
1379┕>Re: C or C++에서 mysql 연동하는법..(긴급....)
장시복
2000-04-24 09:37:12
6777
1370mysql에서 float type 변수 비교가 않됩니다. --급해요 부탁부탁
배인호
2000-04-22
6857
1371┕>Re: mysql에서 float type 변수 비교가 않됩니다. --급해요 부탁부탁
정재익
2000-04-22 14:58:42
7364
1365mysqlimport의 사용법?
IOI
2000-04-22
6473
1362Mysql과 GTK+연동???
장시복
2000-04-22
6538
1364┕>Re: Mysql과 GTK+연동??? -&gt; 사이트 연것 축하
문태준
2000-04-22 09:30:53
6640
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.018초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다