Hi, i've been working on this simple homework assignment and the only thing stopping me from finishing it is passing a c++ variable to a mysql query using mysql_query. I've searched around for about an hour and every potential solution I have found hasn't worked, so I figured maybe if someone took a look at the exact code I had they could help. So here it is.
#include <iostream>
#include <mysql.h>
using namespace std;
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;
int main()
{
mysql_init(&mysql);
connection =mysql_real_connect(&mysql,"students","********","********","********",0,0,0);
if(connection == NULL){
cout << "ERROR";
cout << mysql_error(&mysql)<<endl;
return 1;
}
int num;
cout << "Please enter a customer number: " << endl;
cin >> num;
query_state = mysql_query(&mysql, "select ORDER_DATE FROM ORDERS WHERE ORDER_NUM =" + num);
if (query_state !=0) {
cout << mysql_error(connection) << endl;
return 1;
}
result = mysql_store_result(connection);
while ( ( row = mysql_fetch_row(result)) != NULL )
{
cout << row[0] << endl;
}
return 0;
}
I put ***'s in for privacy. Any help would be greatly appreciated.