- 论坛徽章:
- 5
|
源代码:
- #include <stdio.h>
- #include <WinSock.h>
- #include <mysql.h>
- #include <mysql_com.h>
- #include <mysql_version.h>
- #include <my_alloc.h>
- main()
- {
- char mysqlServer[20] = "localhost";
- char query[300];
- MYSQL myData;
- MYSQL_RES *res;
- MYSQL_FIELD *fd;
- MYSQL_ROW row;
- int rowCount = 0;
- int colCount = 0;
- int i, j;
- //======================================
-
-
- mysql_init(&myData);//
-
- if (!mysql_real_connect(&myData,"localhost", "root", "111111", "gkdb",3306,NULL,0))
- {
- printf("connect mysql error!\n");//==============连接数据库错误=================
- return 0;
- }
- //================================================================================
-
- sprintf(query,"select * from code_t ");
-
- if( mysql_query(&myData, query) != 0 )
- {
- printf("query error!\n");
- return 0;
- }else
- {
- res = mysql_store_result(&myData);
- rowCount = (int) mysql_num_rows( res );
- colCount = (int) mysql_num_fields( res );
-
- while (fd= mysql_fetch_field(res))
- {
- printf("%s\t",fd->table);
- printf("%s\t",fd->name);
- printf("%s\t",fd->org_table);
- printf("%s\t", fd->db) ;
-
- }
- printf("\n");
- while (row = mysql_fetch_row(res) )
- {
- for( j = 0; j < colCount; j++)
- {
- printf("[ %s ] ", row[j] );
- } // end for
- printf("\n");
- }
- }
- mysql_free_result(res); //释放结果集
- mysql_close(&myData);
-
- }
复制代码 |
|