- 转载:http://bbs.chinaunix.net/thread-1344019-1-1.html
- #include
- #include
- #include
- #include
- #include
- #include
- main()
- {
- char mysqlServer[20] = "localhost";
- char query[300];
- MYSQL myData;
- MYSQL_FIELD *fd;
- mysql_init(&myData);
- //连接数据库mysql
- if (!mysql_real_connect(&myData,"localhost", "root", "", "test",3306,NULL,0))
- {
- printf("connect mysql error!\n");
- return 0;
- }
- sprintf(query,"INSERT INTO test1(name,gender) values ('kbg','M')");
- if(mysql_query(&myData,query)!=0){ //执行插入语句
- {
- printf("insert data error");
-
- }else
- {
- printf("insert data success");
- }
-
- mysql_close(&myData);
- }
09-05 14:54