The test code is as follows:
Query operations
#include <mysql/mysql.h>
#include <stdio.h>
#include <stdlib.h>
#define HOST "localhost"
#define USERNAME "User name"
#define PASSWORD "Password"
#define DATABASE "Publicresourcesdb"
int main (void)
{
MySQL MySQL;
Mysql_row ROW;
Mysql_res *result;
unsigned int num_fields;
unsigned int i;
Mysql_init (&mysql);
if (!mysql_real_connect (&mysql, HOST, USERNAME, PASSWORD, DATABASE, 0, NULL, 0))
{
printf ("Connection failed,%s\n", Mysql_error (&mysql));
}
mysql_query (&mysql, "Set names UTF8");
if (!mysql_query (&mysql, "select * from"))
{
result = Mysql_store_result (&mysql);
if (!result)
{
Perror ("result error.");
Exit (1);
}
Num_fields = Mysql_num_fields (result);
while (row = mysql_fetch_row (result))
{
for (i=0; i<num_fields; i++)
{
printf ("%s\t", Row[i]);
}
printf ("\ n");
}
Mysql_free_result (result);
}
Mysql_close (&mysql);
return 0;
}