gpt4 book ai didi

c++ - 在 C++ 项目中使用 mysql_query 进行多个查询

转载 作者:可可西里 更新时间:2023-11-01 08:33:39 26 4
gpt4 key购买 nike

所以,这不适用于 mysql_query。

我严格使用 c++,我没有使用 php。

我希望执行此双重查询,以便在并发用户创建 ID 的交易系统中始终拥有唯一 ID。

mysql_query(connection, \
"INSERT INTO User() VALUES (); SELECT LAST_INSERT_ID(); ");

它在 MySql 数据库中完美运行,但我需要将它添加到 Eclipse(我使用的是 Ubuntu 12.04 LTS)。

我的应用程序很大,我不想更改为 mysqli,如果可以的话,但如果没有其他方法也可以。

你能帮我解决这个问题吗?提前致谢。

最佳答案

根据 MySQL C API 文档:

MySQL 5.6 also supports the execution of a string containing multiple statements separated by semicolon (“;”) characters. This capability is enabled by special options that are specified either when you connect to the server with mysql_real_connect() or after connecting by calling` mysql_set_server_option().

和:

CLIENT_MULTI_STATEMENTS enables mysql_query() and mysql_real_query() to execute statement strings containing multiple statements separated by semicolons. This option also enables CLIENT_MULTI_RESULTS implicitly, so a flags argument of CLIENT_MULTI_STATEMENTS to mysql_real_connect() is equivalent to an argument of CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS. That is, CLIENT_MULTI_STATEMENTS is sufficient to enable multiple-statement execution and all multiple-result processing.

因此,您可以在单个 mysql_query() 调用中提供多个语句,以分号分隔,假设您使用 mysql_real_connect 设置您的 mysql 连接有点不同。您需要将以下标志作为最后一个参数传递:CLIENT_MULTI_STATEMENTS,其文档说:

Tell the server that the client may send multiple statements in a single string (separated by “;”). If this flag is not set, multiple-statement execution is disabled. See the note following this table for more information about this flag.

参见 C API Support for Multiple Statement Execution22.8.7.53. mysql_real_connect()更多详细信息。

关于c++ - 在 C++ 项目中使用 mysql_query 进行多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270562/

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