2008/10/30 21:38
[Linux C]
#include <stdlib.h>
#include <stdio.h>#include "mysql.h"
int main(int argc, char *argv[]) {
MYSQL *conn_ptr;
conn_ptr = mysql_init(NULL);
if(!conn_ptr) {
fprintf(stderr, "mysql_init failed\n");
return 1;
}conn_ptr = mysql_real_connect(conn_ptr,"호스트명","계정ID","계정PW","데이터베이스명",0,NULL,0);
if(conn_ptr) {
printf("Connection success\n");
}else{
printf("Connection failed\n");
}mysql_close(conn_ptr);
return 0;
}
이렇게. 쳐넣고 testmysql.c 로 저장하자. 그리고
컴파일을 해보자.
gcc -I/usr/include/mysql testmysql.c -lmysqlclient -o testmysql이제 실행하면 접속/실패 메시지를 볼수 있다.



