gpt4 book ai didi

c++ - 我无法使用 C++ 从 mysql 数据库中检索数据

转载 作者:行者123 更新时间:2023-12-02 10:32:56 34 4
gpt4 key购买 nike

嘿,我是 C++ 的新手,我在我的代码中遇到了这个错误,错误:“const char [35]”和“const char [2]”类型的无效操作数到二进制“operator+”
我坚持那些情况,
这是我的代码

#include <iostream>
#include <bits/stdc++.h>
#include <windows.h>
#include <mysql.h> //header mysql
#include <sstream> //merubah semua tipe data yang diinputkan user ke string
#include <algorithm> //untuk menggunakan fungsi begin, end
#include <regex>

using namespace std;

int main()
{
string hadis;
MYSQL* conn; //for connection handler
MYSQL_ROW row, row1; // return data as array of strings
MYSQL_RES* res; //hold the result set
int num_fields;
conn = mysql_init(0); //initialaize connection handler. dont change!
conn = mysql_real_connect(conn, "192.168.43.205", "ibrahim", "hadis", "hadis", 0, NULL, 0);
if(conn)
{
int qstate = mysql_query(conn, "SELECT Isi_Indonesia FROM malik");
if(!qstate)
{
res = mysql_store_result(conn); //
num_fields = mysql_num_fields(res);
while(row = mysql_fetch_row(res)) //mysqli fetch srray, Fetch all rows from the result
{
data = row[0];
regex reg("[^\\w]+");
data = regex_replace(data, reg, " ");
//cout << data <<"\n\n";
istringstream stm(data) ;
while( stm >> hadis ) // read white-space delimited tokens one by one
{
for(int i = 0; i < num_fields; i++)
{
const char *hadiss = hadis.c_str();
if(hadiss != NULL)
{
cout << hadiss << endl;
/* 1st error */ mysql_query(conn,"SELECT kata FROM totalkata_malik2 WHERE kata='"+hadiss+"'"); //the 1st error
res = mysql_store_result(conn);
int num_fields = mysql_num_fields(res);
while ((row = mysql_fetch_row(res)))
{
/* 2nd error */ string query2 = "INSERT INTO totalkata_malik2(kata,total) VALUES ('"+hadiss+"',1)"; // the code that got 2nd error
mysql_query(conn, query2.c_str());
}

}

else
cout << "NULL" << endl;

}
}

}
}
}
return 0;
}

我试图搜索一些引用资料,但我无法理解它们,因此我不知道我必须做什么来解决这两个错误

最佳答案

您没有写第二个错误,但您可能想做 std::string(hadiss),
如在

string query2 = "INSERT INTO totalkata_malik2(kata,total) VALUES ('"+std::string(hadiss)+"',1)";

关于c++ - 我无法使用 C++ 从 mysql 数据库中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61636340/

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