Dear All,

            I want to connect MYSQL with following C application , while i'm 
trying to retrive the query generated , its corrupting the memory. 

     Is there any solution , to retrive the query generated with out any memory 
crashes?

     Please help me to solve this problem.

code as follows,

-------------------------------------------------------------------------------------------------------------------------------------------------------------

  1.. #include <stdio.h>
  2.. #include <stdlib.h>
  3.. #include <string.h>
  4.. #include "mysql.h"
  5.. ?
  6.. int main()
  7.. {
  8.. MYSQL *conn;
  9.. MYSQL_RES *res;
  10.. MYSQL_ROW row;
  11.. MYSQL_FIELD *field;
  12.. unsigned int i = 0;
  13.. char table_type[30];
  14.. char buffer[200];
  15.. unsigned int num_fields;
  16.. char *server = "localhost";
  17.. char *user = "root";
  18.. char *password = ""; /* set me first */
  19.. char *database = "test";
  20.. conn = mysql_init(NULL);
  21.. ?
  22.. /* Connect to database */
  23.. if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 
0))
  24.. {
  25.. fprintf(stderr, "%s\n", mysql_error(conn));
  26.. exit(1);
  27.. }
  28.. ?
  29.. if(mysql_ping(conn))
  30.. {
  31.. printf("error in connection \n");
  32.. exit(1);
  33.. }
  34.. sprintf(table_type, "method");
  35.. ?
  36.. sprintf(buffer, "select mid, mname from %s;", table_type);
  37.. mysql_query(conn, buffer);
  38.. res = mysql_store_result(conn);
  39.. num_fields = mysql_num_fields(res);
  40.. 
  41.. while ((row = mysql_fetch_row(res)) != NULL)
  42.. {
  43.. for(i = 0;i < num_fields;i++)                                   //here 
is the problem , num_fields is corrupting 
  44.. printf("%s\n", row[i]?row[i]:"NULL");
  45.. }
  46.. mysql_free_result(res);
  47.. mysql_close(conn);
  48.. return 0;
  49.. }
-----------------------------------------------------------------------------------------------------------------------------------------------------------------


Regards, 
Raviraj
-----------------------------------------
mobile : (91) (0) 9742293013
www.vinjey.com
P Think before you print
/* work should be challenging 
and the challenge should be fun */ 

Reply via email to