c mysql查询多个条件_在c ++项目中使用mysql_query进行多个查询

bd96500e110b49cbb3cd949968f18be7.png

So, this will not work with mysql_query.

I am strictly working with c++ and I am not using php.

I want this double query to be executed so that I will always have a unique ID in a transaction system with concurrent users creating IDs.

mysql_query(connection, \

"INSERT INTO User() VALUES (); SELECT LAST_INSERT_ID(); ");

It works in MySql DataBase perfectly, but I need to add it to Eclipse( I am using Ubuntu 12.04 LTS).

My application is quite big and I would not like to change to mysqli, if this is possible but if there is no other way it will be ok.

Can you help me with this? Thanks in advance.

解决方案

According to the MySQL C API documentation:

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().

And:

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.

So, you can supply several statements in a single mysql_query() call, separated by a semicolon, assuming you set up your mysql connection a bit differently, using mysql_real_connect.

You need to pass the following flag as the last argument: CLIENT_MULTI_STATEMENTS, whose documentation says:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值