Hi
i wrote a program which get query from mysql and store in varible in C.but it can't convert Object mysql ro int.any idea??
#include <stdio.h>
#include <string.h>
#include <mysql.h>
#include <stdlib.h>
int main(){
char *email, name[30], domain[30], query[100], tmp[200];
int i=0,j,k;
unsigned int size;
email = "test@example.com";
char ch;
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "root"; /* set me first */
char *database = "mydb";
do{
ch=email[i];
i++;
}while(ch != '@');
for(j=0;j<i-1;j++){
name[j]=email[j];
}
name[j]='\0';
for(k=0,++j;email[j];j++,k++){
domain[k]=email[j];
}
sprintf(query, "select size_file from mydbuser where username='%s' && ",name);
sprintf(tmp, "domains='%s'",domain);
strcat(query, tmp);
conn = mysql_init(NULL);
// Connect to database
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
// send SQL query
if (mysql_query(conn, query)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
// output table name
//printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
size=(int)row[0];
printf("%s\n",row[0]);
// close connection
mysql_free_result(res);
mysql_close(conn);
return 0;
}