Ad

Using Mysql C API For C++ Codes

- 1 answer

I'm writing a c++ connector to a mysql datdabase and the only thing that I have is mysql.com references and everything here is for C and I wanted to see if it's ok to use this API for c++ codes or not? for example for the affected row we have

 char *stmt = "UPDATE products SET cost=cost*1.25
              WHERE group=10";
mysql_query(&mysql,stmt);
printf("%ld products updated",
       (long) mysql_affected_rows(&mysql));

and is it same for cpp?

And I'm talking about this because we have somthing like this for c++ but not for C:

sql::ResultSet  *res;
while(res->next()){
        columnNames[i-1] = res->getString(i);
        i++;
    }

note that this just a part of a code

Ad

Answer

Yes, any C library can be used in C++ code. Just like Joachim Pileborg has mentioned in the comment.

this is just a code snippet from one of my project. I think you are looking for something like this.

MYSQL_ROW row;

  while ((row = mysql_fetch_row(result))) 
  { 
      for(int i = 0; i < num_fields; i++) 
      { 
        // printf("%s \n", row[i] ? row[i] : "NULL");
         char* new = malloc(100);
         prtid[a]= new;
         strcpy(prtid[a],row[i]);

      } 
      a++;

  }

Here is the link, If you want to study more

Ad
source: stackoverflow.com
Ad