如何将 table 的值传递给 c++ 的变量在mysql中使用select++

发布于 2024-09-25 00:35:50 字数 708 浏览 1 评论 0原文

如何从表中选择一个值并将其存储在我的 sql++ 中的变量中,

例如从员工中选择姓名;

用 c++ 编写这个查询,然后将名称存储在变量 e_name 中,


我用 google 搜索,我知道 mysql++ 教程告诉了这段代码,但我的连接方式不同......你能看出这有什么问题吗?

mysql_init(&mysql); connection = mysql_real_connect(&mysql,..........)

deck for 连接,否则执行此操作

std::ostringstream query3;
query3<<"select pipe_id from pipe where version_id='"<<id<<"'";
std::storeQueryResult ares=query3.store();
for(size_t i=0;i<ares.num_rows();i++)
    cout<<ares[i]["version_id"]<<ares[i]["pipe_id"]<<std::endl;
mysql_query(&mysql,query3.str().c_str());

,错误是 store 不是 ostringstream 的成员。 这就是我的理解,但在上面我应该如何进行 任何提示

How to select a value from a table and store in a variable in my sql++

e.g select name from employee;

write this query in c++ and then store the name in variable e_name


I googled and I know the mysql++ tutorials tell this code but I was connecting differently... can you see what is the problem with this.

mysql_init(&mysql);
connection = mysql_real_connect(&mysql,..........)

dheck for connection else do this

std::ostringstream query3;
query3<<"select pipe_id from pipe where version_id='"<<id<<"'";
std::storeQueryResult ares=query3.store();
for(size_t i=0;i<ares.num_rows();i++)
    cout<<ares[i]["version_id"]<<ares[i]["pipe_id"]<<std::endl;
mysql_query(&mysql,query3.str().c_str());

the erroer is that store is not a member of ostringstream.
thats i understood but in above so how should i proceeed
any hints

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

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

发布评论

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

评论(1

玩物 2024-10-02 00:35:50

请参阅 mysql++ 教程:

http://tangentsoft.net/mysql++/doc/ html/userman/tutorial.html#simple

相关代码:

mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
    cout << "We have:" << endl;
    for (size_t i = 0; i < res.num_rows(); ++i) {
        cout << '\t' << res[i][0] << endl;
    }
}

在本例中,查询结果存储在res变量中。

See the mysql++ tutorial:

http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#simple

The relevant code:

mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
    cout << "We have:" << endl;
    for (size_t i = 0; i < res.num_rows(); ++i) {
        cout << '\t' << res[i][0] << endl;
    }
}

In this example, the results of the query are stored in the res variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文