如何通过 C++要插入 c++ 的变量使用 Mysql ++

发布于 2024-09-24 02:54:44 字数 588 浏览 1 评论 0原文

几天来我一直在努力处理代码,任何人都可以帮助

std::string str=uri_req1.substr(found+1);
char query[2000];
sprintf(query,"Insert into publish VALUES('%s','NO')",str);

我收到以下警告,并且值未插入到表中,

warning: cannot pass objects of non-POD type ‘struct std::string’
through ‘...’; call will abort at runtime
warning: format ‘%s’ expects type ‘char*’, but
argument 3 has type ‘int’

我尝试过其他事情,

string query;
query="Insert into publish values('";
query+=str;
query+="','NO')";
  mysql_query(&mysql,query);

但这也从未奏效 请帮忙

I am struggling with the code from few days can anyone help

std::string str=uri_req1.substr(found+1);
char query[2000];
sprintf(query,"Insert into publish VALUES('%s','NO')",str);

I am getting following warnings and value is not inserted in the tables

warning: cannot pass objects of non-POD type ‘struct std::string’
through ‘...’; call will abort at runtime
warning: format ‘%s’ expects type ‘char*’, but
argument 3 has type ‘int’

other thing I tried was

string query;
query="Insert into publish values('";
query+=str;
query+="','NO')";
  mysql_query(&mysql,query);

but this also never worked
kindly help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-10-01 02:54:44

我可能会使用 stringstream 来组装字符串:

std::ostringstream query;

query << "Insert into publish values('" << str << "', 'NO')";
mysql_query(&mysql, query.str().c_str());

I'd probably use a stringstream to assemble the string:

std::ostringstream query;

query << "Insert into publish values('" << str << "', 'NO')";
mysql_query(&mysql, query.str().c_str());
盛夏尉蓝 2024-10-01 02:54:44

这肯定会起作用;)

string query;
query="Insert into publish values('";
query+=str; 
query+="','NO')"; 
mysql_query(&mysql,query.c_str());

This will surely work ;)

string query;
query="Insert into publish values('";
query+=str; 
query+="','NO')"; 
mysql_query(&mysql,query.c_str());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文