gpt4 book ai didi

mysql - C++ 如何包含它?

转载 作者:行者123 更新时间:2023-11-29 23:45:57 25 4
gpt4 key购买 nike

所以。

#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 数据库表。所以我可以从本地主机/索引读取它,好吗?教程,欢迎任何对我有帮助的事情。预先感谢您!

最佳答案

您的项目是使用预编译 header 构建的,这意味着一些常见 header 被预编译成编译器可以更快读取的形式,从而节省编译时间。

但是,有一个警告:这条线

#include "stdafx.h"

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com