所以
#include <mysql/mysql.h>
#include <stdio.h>
int main(){
MYSQL mysql;
MYSQL_ROW row;
MYSQL_RES *result;
unsigned int num_fields;
unsigned int i;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,"localhost","kevin","****","my_db",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
}
else {
if(mysql_query(&mysql, "SELECT * FROM my_table"));
//here goes the error message <!-- s:o --><img src=\"{SMILIES_PATH}/icon_surprised.gif\" alt=\":o\" title=\"Surprised\"><!-- s:o -->)
else {
result = mysql_store_result(&mysql);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
{
printf("[%.*s] \t", (int) lengths[i], row[i] ? row[i] : "NULL");
}
printf("\n");
}
}
}
return 0;
}
这是我的代码。但我不断给我这个错误:
1>------ Build started: Project: changedatamysql, Configuration: Release Win32 ------
1>Build started 20.9.2014 16:51:51.
1>InitializeBuildStatus:
1> Touching "Release\changedatamysql.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> changedatamysql.cpp
1>changedatamysql.cpp(1): warning C4627: '#include <mysql/mysql.h>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>changedatamysql.cpp(37): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.52
==========构建:0成功,1失败,0最新,0跳过==========
那么这有什么用呢? 我试图使它,以便该程序将数据发送到我的mysql数据库表。 所以我可以从我的localhost / index读取它好吗? 教程,欢迎任何帮助我。 提前谢谢!
答案 0 :(得分:0)
您的项目是使用预编译的头构建的,这意味着一些常见的头文件被预先编译成一种形式,可以更快地为编译器读取,从而节省编译时间。
然而,有一个警告:行
#include "stdafx.h"
必须 是源文件中第一个非注释,非空行。