title: Copy records from a table of a database to a table of same name of other database through c++
body: <p>There is a database named "rfidacs" and there is a table in that database named "Alarm". Now I want to copy all the records of Alarm table to a table of same name "Alarm" of another database named DbDemo. I have written this code. Kindly correct it .I am programming on eclipse IDE on linux.</p>
  
  <pre><code>int DBDEMO :: demoTest()
  
  
  {
  
  MYSQL_ROW row;
  MYSQL *conn, *conn1;
  
  conn  = mysql_init(NULL);
  conn1 = mysql_init(NULL);
  
  if(conn == NULL)
  {
      fprintf(stderr,"mysql_init() failed");
      exit(1);
  }
  if(conn1 == NULL)
      {
          fprintf(stderr,"mysql_init() failed");
          exit(1);
      }
  if( mysql_real_connect(conn1, "localhost", "root", "rgb123", "DbDemo", 0, NULL, 0)==NULL)
      {
          finish_with_error(conn1);
      }
  
  if( mysql_real_connect(conn, "localhost", "root", "rgb123", "rfidacs", 0, NULL, 0)==NULL)
  {
      finish_with_error(conn);
  }
  
  if(mysql_query(conn,"select * from Alarm"))
          {
              finish_with_error(conn);
          }
  MYSQL_RES *result = mysql_store_result(conn);
  
  if(result == NULL)
  {
      finish_with_error(conn);
  }
  
  int num_fields = mysql_num_fields(result);
  
  
  while((row=mysql_fetch_row(result)))
  {
      char *temp;
      for(int i=0;i&lt;num_fields;i++)
      {
      temp="Insert into Alarm values (row[i])";
      mysql_query(conn1, temp);
          if(mysql_query(conn1, "Insert into Alarm values row"))
            {
              finish_with_error(conn1);
  
            }
  
      }
  
  }
  
  mysql_free_result(result);
  mysql_close(conn);
  mysql_close(conn1);
  
  }
  return SUCCESS;
  
  
  
  }
  </code></pre>
  
  <p>Thanks in advance</p>