所以。

#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读取它吗?
教程,任何对我有帮助的都欢迎。
先感谢您!

最佳答案

您的项目是使用预编译的标头进行构建的,这意味着某些常见的标头已被预编译为某种形式,可以更快地为编译器读取,从而节省了编译时间。

但是,有一个警告:

#include "stdafx.h"


必须是源文件中的第一行非注释,非空行。

关于mysql - C++ <mysql/mysql.h>如何包含它?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25949507/

10-10 08:26