At 10:42 -0500 6/26/02, rm wrote:
>I'm trying to retrieve a particular field using C API.  When I use this
>select statement from the mysql client it retrievs the correct result:
>
>mysql>SELECT ap_senders FROM mailtable WHERE pw_name='regis' and
>pw_domain='mbpost.com';
>
>But...
>
>In the C function listed below: 
>
>#include <stdio.h>
>#include <mysql.h>
>
>int main(char **args)
>{
>       MYSQL_RES *result;
>       MYSQL_FIELD *field;
>       MYSQL *connection, mysql:
>       int state;
>
>       mysql_init(&mysql);
>       connection = mysql_real_connect(&mysql,"localhost","root","",\
>       "mailtable",0,NULL,0);
>
>       if(connection == NULL) {
>               printf(mysql_error(&mysql));
>               return 1; }
>
>       state = mysql_query(connection, "SELECT ap_senders FROM\ mailtable
>WHERE pw_name='regis' and pw_domain='mbpost.com'");
>
>       if (state != 0) {
>               printf(mysql_error(connection));
>               retrun 1;}
>
>       result = mysql_store_result(connection);
>       printf("Found %d field\n", mysql_num_fields(result));
>
>       while ( ( field = mysql_fetch_field(result)) != NULL) {
>       printf("approved sender ID; %s\n", *field);  //problem here!
>
>       mysql_free_result(result);
>       mysql_close(connection);
>       printf(Done.\n");
>}
>
>It compiles without error or warning but instead of getting the results
>of what is in the field - I get the name of field.  The output is:
>
>Found 1 field
>approved sender ID; ap_senders
>Done.
>
>Of course ap_senders is the field name, not the query result.  So, I'm
>obviously asking for the wrong thing somewhere - any comments or
>suggestions are greatly appreciated.

mysql_fetch_field() fetches column metadata, not column data.
You want mysql_fetch_row() instead.  It's described in the manual.

>
>Regis


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to