问一下一下 mysql_query 怎么才能执行多条混合型语句?

MySql 码拜 8年前 (2015-11-13) 877次浏览
#include <WinSock.h>
#include <windows.h>
#include <mysql.h> 
#include <string> 
#include <iostream> 
using namespace std; 
int main()
{ 
    const char user[] = "root"; 
    const char pswd[] = "891017"; 
    const char host[] = "localhost"; 
    const char table[] = "";       
    unsigned int port = 3306;                
    MYSQL myCont;
    MYSQL_RES *result = NULL;
    MYSQL_ROW sql_row; 
	int res, res2;
    mysql_init(&myCont); 
   if (mysql_real_connect(&myCont, host, user, pswd, 
	   table, port, NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS))
    { 
		res = mysql_query(&myCont, "use test; select * from test1;");//查询 

        if (!res)
        {
			if ((res2 = mysql_more_results(&myCont)) <= 0)
			{
				//...
			}
			else
			{
				printf("[%d]%s", res2, mysql_error(&myCont));
			}
        } 
        else 
        {
            cout << "query sql failed!" << endl;
			printf("[%d]%s", res, mysql_error(&myCont));
        }
    } 
    else 
    {
        cout << "connect failed!" << endl;
    } 
   
    if (result != NULL) 
        mysql_free_result(result);
    mysql_close(&myCont);
    system("pause"); 
    return 0;
}
/*
执行结果:
[1]请按任意键继续. . .
*/
解决方案:10分
你是想要一次执行多个sql,然后接下来读取多个结果集吗
解决方案:10分
不太明白什么意思

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明问一下一下 mysql_query 怎么才能执行多条混合型语句?
喜欢 (0)
[1034331897@qq.com]
分享 (0)