How to send C++ and mysql dynamic mysql queries

前端 未结 3 699
执念已碎
执念已碎 2020-12-21 22:45

Working with Visual Studio, Windows 7 and mysql.h library.

What I want to do is send a MySQL query like this:

mysql_query(conn, \"SELECT pass FROM us         


        
3条回答
  •  抹茶落季
    2020-12-21 23:19

    here is an example:

    #include 
    #include 
    #include 
    using namespace std;
    
    /// ...
    
    string name_value = "Leo Tolstoy";
    
    ostringstream strstr;
    strstr << "SELECT pass FROM users WHERE name='" << name_value << "'";
    
    string str = strstr.str();
    mysql_query(conn, str.c_str());
    

提交回复
热议问题