title: Fetching rows in a MySQL database table using MySQL C API and C++
body: <p>I'm confused when trying to fetch table rows in mysql using C++ with MySQL C API.</p>
  
  <p>I can do it easily in PHP, just because C++ is a strongly-typed language so that we also need to take care of the dirty process..</p>
  
  <p>This is how I done it in PHP</p>
  
  <pre>$data = array();
  $i = 0;
  $query = mysql_query("SELECT * FROM `my_table`");
  while($fetch = mysql_fetch_array($query))
  {
    $data[$i] = $fetch['columntobefetched'];
    $i++;
  }</pre>
  
  <p>But how to do the same in C++ with MySQL API?</p>
  
  <p>Here's my code so far....with a confusing dead end...x__x</p>
  
  <pre>   MYSQL *sqlhnd = mysql_init(NULL);
      mysql_real_connect(sqlhnd, "server", "user", "pass", "database", port, NULL, 0);
  
      mysql_query(sqlhnd, "SELECT * FROM `my_table`");
      MYSQL_RES *confres = mysql_store_result(sqlhnd);
      int totalrows = mysql_num_rows(confres);
      int numfields = mysql_num_fields(confres);
      MYSQL_FIELD *mfield;
  
      while((row = mysql_fetch_row(confres)))
      {
          for(i = 0; i &lt; numfields; i++)
          {
              while(mfield = mysql_fetch_field(confres))
              {
                  mfield-&gt;//??? I'm dead
              }
          }
      }</pre>
  
  <p>Basically I wanted to get a value from a field in the database table and store it to a variable..</p>
  
  <p>Any kind of help would be appreciated :)</p>
  
  <p>Thanks</p>