Help with connecting C++ and MySQL
I need to run a query in MySQL with C++ input. So far I've written this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int E1, Ei;
string sqlquery;
string sqlquery2;
string query;
cout << "E1 = "; cin >> sqlquery;
cout << "Ei = "; cin >> sqlquery2;
sqlquery = "INSERT INTO `e_lookup` SELECT * FROM `mdbase` WHERE `E1` = " + sqlquery;
sqlquery2 = " OR `E1` = " + sqlquery2;
query = strcat (sqlquery, sqlquery2);
cout<< query << endl;
mysql_query(sock, query.c_str());
|
However, the code resulted in this following error:
[Error] cannot convert 'std::string {aka std::basic_string<char>}' to 'char*' for argument '1' to 'char* strcat(char*, const char*)'
|
Can anyone help me with this??
query = strcat (sqlquery, sqlquery2);
Why are you using strcat on C++ type strings ??
Use this:
1 2
|
query += sqlquery;
query += sqlquery2;
|
Well, I actually just learned programming. :)
Is there a shorter way to do this? Other than adding up string?
Topic archived. No new replies allowed.