#include <stdio.h>
#include<stdlib.h>
#include"mysql/mysql.h"
int main()
{
MYSQL*conn_ptr;
MYSQL_RES*res_ptr;
MYSQL_ROW sqlrow;
MYSQL_FIELD*fd;
int res, i, j;
conn_ptr= mysql_init(NULL);
if (!conn_ptr)
{
return EXIT_FAILURE;
}
conn_ptr= mysql_real_connect(conn_ptr,"localhost","root","","testMysql", 0, NULL, 0);
if (conn_ptr)
{
res= mysql_query(conn_ptr,"select * from `monitorStatus` where system_name='sys_8' and site_name='s_9' and equipment_name='e_6' order by timestamp desc limit 10000;");
if (res)
{
printf("SELECT error:%s\n",mysql_error(conn_ptr));
}
else
{
res_ptr= mysql_store_result(conn_ptr);
if(res_ptr)
{
printf("%lu Rows\n",(unsigned long)mysql_num_rows(res_ptr));
j= mysql_num_fields(res_ptr);
while((sqlrow = mysql_fetch_row(res_ptr)))
{
continue;
for(i = 0; i < j; i++)
printf("%s\t", sqlrow[i]);
printf("\n");
}
if (mysql_errno(conn_ptr))
{
fprintf(stderr,"Retrive error:s\n",mysql_error(conn_ptr));
}
}
mysql_free_result(res_ptr);
}
}
else
{
printf("Connection failed\n");
}
mysql_close(conn_ptr);
return EXIT_SUCCESS;
}
Makefile文件: