Home > Back-end >  C language, with a cJSON from mysql database query data into a json format
C language, with a cJSON from mysql database query data into a json format

Time:12-06

Is to traverse the data in the table below as a result, after how encapsulation in cJSON, cJSON should be how to write, not here, I pray god guide

Int main ()
{
MYSQL * conn=NULL;
MYSQL_RES * res=NULL;
MYSQL_ROW row=NULL;

Conn=mysql_init (NULL);
If (mysql_real_connect (conn, host, user, password, db_name, 0, NULL, 0)==NULL)
{
Fprintf (stderr, "% s \ n", mysql_error (conn));
The exit (1);
}

Char []="SQL select g.g roup_id, g.p arent_id, g.a ncestors, g.g roup_name, g.o rder_num, g.s tatus \
The from sys_group g \
Where g.p arent_id=(SELECT group_id from sys_group_handle where handle_num=1001),
And g.d el_flag='0' \
The order by order_num asc ";
If (mysql_query (conn, SQL))
{
Fprintf (stderr, "% s \ n", mysql_error (conn));
The exit (1);
}
Res=mysql_use_result (conn);
While ((row=mysql_fetch_row (res))!=NULL)
Printf (" % s \ % s \ \ t t t % s % s \ \ t t % s \ n ", the row [0], row [1], the row [2], the row [3], the row [4]);


The mysql_free_result (res);
Mysql_close (conn);
return 0;
}

CodePudding user response:

3 2 0,1.2 la-la-la 1
Additional output format like this appearance, also did not add a field name, only through the data
  • Related