tel_number 테이블 구조는
--------------------------------------------------
| Field | Type | Null | Key | Defalt | Extra |
--------------------------------------------------
| no | int(11) | | PRI | NULL | auto_increment |
| tel_number | char(20) | | MUL | | |
--------------------------------------------------
이렇습니다.
소스는
#include <stdio.h>
#include <string.h>
#include \mysql.h\
#define HOST \localhost\
#define USER \lns\
#define PASSWD \no4822\
#define DB_NAME \km_db\
int main()
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char query[128];
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, HOST, USER, PASSWD, DB_NAME, 0, (char *)NULL, 0))
{
fprintf(stderr, \connection error : %d - %s
\, mysql_errno(&mysql), mysql_error(&mysql));
exit(1);
}
strcpy(query, \select * from tel_number\);
mysql_real_query(&mysql, query, strlen(query));
res = mysql_store_result(&mysql);
if(!res)
{
mysql_close(&mysql);
fprintf(stderr, \query error or empty set : %d - %s
\, mysql_errno(&mysql), mysql_error(&mysql));
exit(1);
}
while(row = mysql_fetch_row(res))
printf(\%d : %s
\, atoi(row[0]), row[1]);
mysql_free_result(res);
mysql_close(&mysql);
exit(0);
}
간단하죠?
좀 도움이 됐으면 좋겠네요..
|