数据库
首页 > 数据库> > mysql连接。关闭。执行sql语句---执行插入insert。返回该插入产生的自增ID

mysql连接。关闭。执行sql语句---执行插入insert。返回该插入产生的自增ID

作者:互联网

执行插入insert。返回该插入产生的自增ID

 

		CStringA db_name="XXX";
		CStringA db_address = "X.X.X.X";
		CStringA db_user = "UUU";
		CStringA db_psd = "PPPP";
		unsigned int db_port = 1234;

		MYSQL mysql;
		if (mysql_init(&mysql) != NULL)
		{
			mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "gb2312");
			INT nTimeout = 3;    //秒
			mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, &nTimeout);
			if (mysql_real_connect(&mysql, db_address, db_user, db_psd, db_name, db_port, NULL, 0))
			{
				CStringA sql = "";
				sql.Format("INSERT into tttt(time) values(now())");
				int id = -123;
				int ret = mysql_query(&mysql, sql);
				if (ret == 0)
				{
					id = mysql_insert_id(&mysql);
				}
			}

			mysql_close(&mysql);
		}

  

标签:insert,自增,int,sql,db,CStringA,插入,mysql,id
来源: https://www.cnblogs.com/XiHua/p/16481587.html