MYSQL_RES *query(char *sql)
{
MYSQL_RES *res;
if (mysql_query(&connection, sql) != 0)
{
fprintf(stderr, "Failed to send query: Error: %s\nsqlstatement:%s\n",\
mysql_error(&connection),sql);
exit(2);
};
res = mysql_store_result(&connection);
return(res);
};
- We declare a variable (res)that will held the result of our query
- mysql_query requires a established connection to a mysql server and a valid sql statement. If the statement gets executed corretly, it returns 0, otherwise you can use the mysql_error function to get the error message.
- And at last mysql_store_result stores the result of our query or NULL if there was an error.
root
2015-09-06