title: how to get out parameters from stored procedure via C Programming API
body: <p>I've done some searches and scrutinized the C Programming API that is here:</p>
  
  <p><a href="http://dev.mysql.com/doc/refman/5.1/en/c-api-prepared-statement-functions.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/c-api-prepared-statement-functions.html</a></p>
  
  <p>Most of it geared towards fetching rows of data that come back, which is easy.  The sproc is being called like this from the C program (I know I should bind the parameters I will...) :</p>
  
  <pre><code>sprintf( cmd, "CALL get_graph_data( \"%s\", \"%s\");", symbol, scope );
  
  if (mysql_query(conn, cmd)) {
        fprintf(stderr, "%s\n", mysql_error(conn));
        exit(1);    
  }
  
  res = mysql_use_result(conn);
  if( res == NULL ) { ;       // how do I get output parameters in this case ?  umm...
  } else {                
     num_fields = mysql_num_fields(res);
     while ((row = mysql_fetch_row(res)) != NULL)
     {   
          do stuff
     } 
  }
  </code></pre>
  
  <p>the SPROC that I am calling looks like this :</p>
  
  <pre><code>create procedure get_graph_data (
      symbol varchar(20),
      period varchar(5),
      OUT status SMALLINT,
      OUT emsg varchar(255)
  )
  </code></pre>
  
  <p>SO - I can't figure out the API calls to get at the two output parameters status and emsg.  also, in the case where the sproc produces zero rows (some validation of user input has to occur in the db without having to make extra calls to do that) then 'res' comes back NULL so not sure how to get at output parameters in that case ...</p>
  
  <p>TIA !</p>