How do i actually get a value from my database and insert the data into a variable in my program?
char filter_exp[] = "";
MYSQL *conn; // pointer to MySQL structure
conn = mysql_init(NULL); // connection handle
// Connect to MySQL database
// host address = localhost, username = root, database = project
mysql_real_connect(conn, "localhost", "root", "", "project", 0, NULL, 0);
mysql_query(conn, "SELECT Filter from setting where transmit='1'");
I need to get a value from the table setting , field = Filter and get the value inside. How do i assign a variable now? i really don't get it. Please help.
MYSQL *conn = 0;
MYSQL_RES *result = 0;
conn = mysql_init(conn);
conn = mysql_real_connect(conn,"localhost","root","","project",0,0,0);
if(conn)
{
if(mysql_query(conn,"SELECT Filter FROM setting WHERE transmit='1'")
{
//query failed
} else {
result = mysql_store_result(conn); // store the result of the query
if(result)
{
unsignedint rows = mysql_num_rows(result); // number of rows in result set
// parse results...
} else {
// empty result set or error
}
mysql_free_result(result); // make sure you call this to free up the memory allocated for the query result
}
mysql_close(conn);
}
EDIT: I have little C++ experience with MySQL I usually use PHP but looked at the API and gave it a shot