#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#define host "localhost"
#define username "root"
#define password "123"
#define database "oa"
MYSQL *conn;
int main()
{
MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i,ret;
FILE *fp;
MYSQL_FIELD *field;
unsigned int num_fields;
conn = mysql_init(NULL);
ret = mysql_options(conn, MYSQL_SET_CHARSET_NAME, "gbk");
mysql_real_connect(conn,host,username,password,database,0,NULL,0);
fp = fopen ( "t_sys_power.out","w");
fprintf(fp,"char set %s\n", mysql_character_set_name(conn));
mysql_query(conn,"SELECT * from t_sys_power ");//WHERE a1='abc'");
res_set = mysql_store_result(conn);
while((field = mysql_fetch_field(res_set)))
{
printf("field name %s\n", field->name);
}
num_fields = mysql_num_fields(res_set);
for(i = 0; i < num_fields; i++)
{
field = mysql_fetch_field_direct(res_set, i);
printf("Field %u is %s\n", i, field->name);
}
while ((row = mysql_fetch_row(res_set)) != NULL)
{
for (i=0; i<mysql_num_fields(res_set); i++)
{
fprintf(fp,"%s\n",row[i] != NULL ? row[i] : "NULL");
}
}
mysql_close(conn);
fclose(fp);
return 0;
}
#include <windows.h>
#include <mysql.h>
#define host "localhost"
#define username "root"
#define password "123"
#define database "oa"
MYSQL *conn;
int main()
{
MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i,ret;
FILE *fp;
MYSQL_FIELD *field;
unsigned int num_fields;
conn = mysql_init(NULL);
ret = mysql_options(conn, MYSQL_SET_CHARSET_NAME, "gbk");
mysql_real_connect(conn,host,username,password,database,0,NULL,0);
fp = fopen ( "t_sys_power.out","w");
fprintf(fp,"char set %s\n", mysql_character_set_name(conn));
mysql_query(conn,"SELECT * from t_sys_power ");//WHERE a1='abc'");
res_set = mysql_store_result(conn);
while((field = mysql_fetch_field(res_set)))
{
printf("field name %s\n", field->name);
}
num_fields = mysql_num_fields(res_set);
for(i = 0; i < num_fields; i++)
{
field = mysql_fetch_field_direct(res_set, i);
printf("Field %u is %s\n", i, field->name);
}
while ((row = mysql_fetch_row(res_set)) != NULL)
{
for (i=0; i<mysql_num_fields(res_set); i++)
{
fprintf(fp,"%s\n",row[i] != NULL ? row[i] : "NULL");
}
}
mysql_close(conn);
fclose(fp);
return 0;
}
//选择->目录:include:C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.0\INCLUDE(compiler option,directories,c++include)
//选择->目录:lib :C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.0\LIB\OPT(compiler option,directories,libraies)
//工程:设置:link:libmysql.lib(update下载libmysql,安装之后,project,projcect option,parameters,linker中输入-lmysql
)
//libmysql.dll拷贝到可执行文件相同目录,或者系统目录下 ......
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2255/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2009-11-23 09:32
评论列表