我想逐列访问。恩。我有3行,有2列。
表格中的值
USERNAME PASSWORD
dipsy pdipsy
poo ppoo
lala plala
在此代码中,它可以打印,但我无法完全控制下次使用的结果,如比较,匹配。我想在数组中执行此操作的原因是因为数组比查询比较或匹配更灵活。我正在使用C Connector API。
#include "mysql.h"
#include <iostream>
using namespace std;
int main()
{
MYSQL * con = mysql_init(NULL);
mysql_real_connect(con, "127.0.0.1", "root", "root", "StackOverFlow", 3306, NULL, 0);
mysql_query(con, "SELECT username, password FROM maccount");
MYSQL_RES * res = mysql_store_result(con);
int num_fields = mysql_num_fields(res);
MYSQL_ROW row;
while((row = mysql_fetch_row(res)))
{
for (int i = 0; i < num_fields; i++)
{
// it print but it can't be control.
cout << row[i] << endl;
// i want like this. row[0] is username field, row[1] is password field
cout << row[0] << row[1];
}
}
mysql_free_result(res);
mysql_close(con);
system("pause");
return 0;
}