Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ MFC程序中mysql查询的输出问题_C++_Mysql_Mfc - Fatal编程技术网

C++ MFC程序中mysql查询的输出问题

C++ MFC程序中mysql查询的输出问题,c++,mysql,mfc,C++,Mysql,Mfc,我目前正在开发一个小型MFC程序,该程序从mysql数据库输出数据。 当我使用不包含任何变量的sql语句时,我可以得到输出 select album from Artists; 但是当我尝试使用一个变量时,程序会编译,但是我没有得到任何输出。 mysql_perform_query(连接,从艺术家中选择相册,其中艺术家=“+m_search_edit””) 下面是mysql\u perform\u查询的函数: MYSQL_RES* mysql_perform_query(MYSQL *conn

我目前正在开发一个小型MFC程序,该程序从mysql数据库输出数据。 当我使用不包含任何变量的sql语句时,我可以得到输出

select album from Artists;
但是当我尝试使用一个变量时,程序会编译,但是我没有得到任何输出。 mysql_perform_query(连接,从艺术家中选择相册,其中艺术家=“+m_search_edit””)

下面是mysql\u perform\u查询的函数:

MYSQL_RES* mysql_perform_query(MYSQL *conn, const char* query)
{
   // send the query to the database
   if (mysql_query(conn, query))
   {
     // printf("MySQL query error : %s\n", mysql_error(conn));
     // exit(1);
   }

   return mysql_use_result(conn);
}
下面是用于输出数据的代码块:

struct connection_details mysqlD;


mysqlD.server = "www.freesqldatabase.com";  // where the mysql database is
mysqlD.user = "**********";  // the root user of mysql 
mysqlD.password = "***********"; // the password of the root user in mysql
mysqlD.database = "***************"; // the databse to pick

// connect to the mysql database
conn = mysql_connection_setup(mysqlD);


CStringA query;
query.Format("select album from Artists where artist = '%s'", CT2CA(m_search_edit));
res = mysql_perform_query(conn, query);



//res = mysql_perform_query (conn, "select distinct artist from Artists");



while((row = mysql_fetch_row(res)) != NULL){
CString str;
UpdateData();

str = ("%s\n", row[0]);

UpdateData(FALSE);
m_list_control.AddString(str);

 }
m_search_edit变量是编辑框的变量。 我正在使用Visual Studio 2008,其中包含一份unicode和一份unicode代码, 我还有一个用VC++6构建的版本。
关于如何使用m_search_edit变量从数据库中获取输出的任何提示???

不是直接的,但是您的查询对于SQL注入是完全开放的。是的,这是唯一一个小型的大学程序,所以SQL注入是我目前最优先考虑的问题。
m_search_edit
变量是
CEdit
对象还是
CString
?H您是如何从编辑控件中获取字符串的?
CEdit::GetWindowText
DDX\u Text
?我还注意到您已经注释掉了
mysql\u perform\u query
中的错误检查,并且正在使用返回的
mysql\u RES*
而没有检查它是否为
NULL
。有可能查询失败了吗你试过验证所有参数是否正确吗?m_search_edit是一个CString,我
也试过它作为一个CEdit。我刚刚意识到我没有任何代码从编辑框中获取字符串。我
m假设这是出了问题,是时候查找GetWindowText了。这看起来一定是一个非常愚蠢的错误,但在我的辩护中,我我以前没有做过很多MFC编程,这是我尝试过的最大的程序。