User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:mysql:mysql.h:mysql_fetch_field

mysql_fetch_field

description of mysql_fetch_field

mysql_fetch_field provides a structure MYSQL_FIELD with information about the current field of quantitative results and advance the field pointer to the next field

#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;
}

output of mysql_fetch_field c example

  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

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/mysql/mysql.h/mysql_fetch_field.txt · Last modified: 2024/02/16 01:12 (external edit)

Impressum Datenschutz