This shows you the differences between two versions of the page.
c:mysql:mysql.h:mysql_fetch_field [2013/02/03 20:19] 127.0.0.1 external edit |
c:mysql:mysql.h:mysql_fetch_field [2024/02/16 01:12] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== mysql_fetch_field ====== | ====== mysql_fetch_field ====== | ||
<code c> | <code c> | ||
+ | MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *result) | ||
</code> | </code> | ||
==== description of mysql_fetch_field ==== | ==== description of mysql_fetch_field ==== | ||
- | mysql_fetch_field is in work by code-reference.com \\ | + | mysql_fetch_field provides a structure [[c:mysql:mysql.h:mysql_field|MYSQL_FIELD]] with information about the current field of quantitative results and advance the field pointer to the next field |
- | if you are faster... don't hasitate and add it | + | |
<code c> | <code c> | ||
- | no example at the moment | + | #include <stdio.h> /* including standard library */ |
+ | #include <mysql/mysql.h> | ||
+ | |||
+ | MYSQL *my; | ||
+ | MYSQL_RES *result; | ||
+ | MYSQL_FIELD *field; | ||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | |||
+ | char host[20]; | ||
+ | char user[20]; | ||
+ | char pass[20]; | ||
+ | |||
+ | my = mysql_init(NULL); | ||
+ | |||
+ | sprintf(host,"localhost"); | ||
+ | sprintf(user,"username"); | ||
+ | sprintf(pass,"password"); | ||
+ | |||
+ | if (my == NULL ) { | ||
+ | printf("Cant initalisize MySQL\n"); | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | if( mysql_real_connect (my,host,user,pass,NULL,0,NULL,0) == NULL) { | ||
+ | printf("Error cant login\n"); | ||
+ | } else { | ||
+ | printf("Login correct\n"); | ||
+ | } | ||
+ | |||
+ | |||
+ | mysql_select_db(my, "test"); | ||
+ | |||
+ | mysql_query(my, "SELECT * FROM collection LIMIT 1;"); | ||
+ | result = mysql_store_result( my ); | ||
+ | |||
+ | while (field = mysql_fetch_field(result)) { | ||
+ | |||
+ | printf("name %s \t\t", field->name); | ||
+ | printf("name_length: %i\n", field->name_length); | ||
+ | |||
+ | if ( IS_NUM ( field->type ) ) | ||
+ | printf("field is numeric\n"); | ||
+ | |||
+ | /* | ||
+ | printf("field->org_name %s\n", field->org_name); | ||
+ | printf("field->org_name_length %i\n", field->org_name_length); | ||
+ | |||
+ | printf("field->table %s\n", field->table); | ||
+ | printf("field->table_length %i\n", field->table_length); | ||
+ | |||
+ | printf("field->org_table %s\n", field->org_table); | ||
+ | printf("field->org_table_length %i\n", field->org_table_length); | ||
+ | |||
+ | printf("field->db %s\n", field->db); | ||
+ | printf("field->db_length %i\n", field->db_length); | ||
+ | |||
+ | printf("field->catalog %s\n", field->catalog); | ||
+ | printf("field->catalog_length %i\n", field->catalog_length); | ||
+ | |||
+ | printf("field->def %s\n", field->def); | ||
+ | printf("field->def_length %i\n", field->def_length); | ||
+ | |||
+ | printf("field->length %li\n", field->length); // unsigned long | ||
+ | printf("field->max_length %li\n", field->max_length); // unsigned long | ||
+ | |||
+ | printf("field->flags %u\n", field->flags); // unsigned long | ||
+ | */ | ||
+ | |||
+ | } | ||
+ | |||
+ | mysql_close(my); | ||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
===== output of mysql_fetch_field c example ===== | ===== output of mysql_fetch_field c example ===== | ||
- | no example at the moment | + | Login correct |
+ | name id name_length:2 | ||
+ | field is numeric | ||
+ | name name name_length:4 | ||
+ | name title name_length:5 | ||
+ | name published name_length:9 | ||