#include <iostream>
#include<mysql/mysql.h>
using namespace std;
MYSQL *con;
MYSQL_RES *res;
MYSQL_ROW row;
int main() {
char server[20] = "localhost";
char user[20] = "root";
char password[20] = "123456";
char database[20] = "mystudent";
con = mysql_init(NULL);
if (!mysql_real_connect(con, server, user, password, database, 0, NULL, 0)) {
cout << "connect failed" << endl;
}
mysql_set_character_set(con, "utf8");
if (mysql_query(con, "select * from student")) {
cout << "query failed";
}
res = mysql_use_result(con);
while ((row = mysql_fetch_row(res)) != NULL) {
cout << row[0] << " " << row[1] << " " << row[2] << " " << endl;
}
mysql_free_result(res);
mysql_close(con);
return 0;
}