I'm curious about the following section of code:
==========================================
f (res) // there are rows
{
num_fields = mysql_num_fields(res);
printf("number of fields = %d\n", num_fields) ;
row = mysql_fetch_row(res) ;
if(row < 0) printf("Ahhh... No Rows\n") ;
printf("ser = %s\n", row[0]) ;
==========================================
I think it should be...
if(row == 0)
printf("Ahhh... No Rows\n") ;
else
printf("ser = %s\n", row[0]) ;
Here's a code snippet to get the values of each column in a row.
==================================================
//stores the row values in a char array and returns the length of the array 'row_values'.
//'row_values' will never be null.
int get_row_values(MYSQL_RES* result, char** &row_values)
{
if(result == NULL)
{
row_values = new char*[0];
return 0;
}
MYSQL_ROW row = mysql_fetch_row(result);
//I really should perform error checking
unsigned int num_fields = mysql_num_fields(result);
unsigned long* lengths = mysql_fetch_lengths(result);
row_values = new char*[num_fields];
for(unsigned int i = 0; i < num_fields; i++)
{
unsigned long field_length = lengths
;
row_values = new char[field_length + 1];
memset(row_values, 0, field_length + 1);
memcpy(row_values, row, field_length);
}
return num_fields;
}
===========================================
Also, check the docs for mysql_fetch_lengths and mysql_fetch_row.
http://dev.mysql.com/doc/refman/4.1/en/mysql-fetch-row.html
http://dev.mysql.com/doc/refman/4.1/en/mysql-fetch-lengths.html