안녕하세요~~^^
바쁘신데 자꾸질문을 드려 죄송합니다!
울트라 슈퍼 초보라 이렇게 답답한질문들을 하오니 부디
굽어 살펴주시옵서예!
C언어로 MYSQL을 연동할려고 다음과같이
gcc test.c -o test -lnsl -I/usr/local/mysql/include/mysql
-L/usr/local/mysql/lib/mysql -lmysqlclient
C파일을 컴파일하니 아무런 에러문이 없이 컴파일이 되더라구요!
근데 생성된 TEST*실행파일을 실행하니 아무런현상도
일어나지 않고 바로 다음 프롬프트로 넘어가더라구요!
~># test 엔터
~>#
이렇게 되는 이유가 뭔가요? 제가 C파일을 잘못 짠건가요~아님 데이터베이스문제인가요?
아님 다른 환경설정을 해주어야 하는건가요?(다른일반 C파일은 실행이되더라구요!)
설명에 도움이 될까쉽어서 데이터베이스 생성 과정과 C소스를 아래에 올립니다!
도움기다리겠습니다! 감사합니다~~~꾸벅^^
mysql>show databases;
+-----------+
| Databases |
+-----------+
| mysql |
| test |
+-----------+
mysql>use test
mysql>show tables;
+--------+
| Tables |
+--------+
| member | // member는 미리만들어 놓았읍니다
+--------+
mysql>desc member;
+------+--------------+-------+---------+--------------+
|Field | Type Null |Key |Default |Extra |
+------------------------------------------------------+
|id | int(11) |PRI |0 |auto_increment|
+------------------------------------------------------+
|name | varchar(20) |YES |NULL | |
+------------------------------------------------------+
|title | varchar(30) |YES |NULL | |
+------+--------------+-------+---------+--------------+
mysql>select * from member;
+-----+--------+------+
| id | name | title|
+---------------------+
| 1 | lee | good |
+---------------------+
| 2 | sun | very |
+-----+--------+------+
이상이 데이터베이스이구요 아래는 test.c의 내용입니다.
#include<sys/time.h>
#include<stdio.h>
#include</usr/include/mysql/mysql.h>
int main(char **args){
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection,mysql;
int state;
mysql_init(&mysql);
connection=mysql_real_connect(&mysql,"localhost","","","test",0,"",0);
if(connection==NULL){
printf(mysql_error(&mysql));
printf("mysql unconnect Fail");
return 1;
}
state=mysql_query(connection,"SELECT name,title FROM member");
if(state!=0){
printf(mysql_error(connection));
printf("mysql connection OK");
return 1;
}
result=mysql_store_result(connection);
printf("rows : %d
",mysql_num_rows(result));
while((row=mysql_fetch_row(result))!=NULL){
printf("name: %s, title: %s
", (row[0] ? row[0] : "NULL"),(row[1] ? row[1] : "NULL"));
}
mysql_free_result(result);
mysql_close(connection);
printf("Done.
");
}
|