Output problem in mysql query in MFC program
- by D.Gaughan
Im currently working on a small MFC program that outputs data from a mysql database.
I can get output when im using an sql statement that does not contain any variable eg.
select album from Artists;
but when i try to use a variable the program compiles but i get no output eg.
mysql_perform_query(conn,select album from Artists where artists = '"+m_search_edit"'")
Here is the function for mysql_perform_query:
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);
}
And here is the code block for outputting the data:
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);
}
The m_search_edit variable is the variable for an edit box.
I am using Visual Studio 2008 with one copy of this program unicode and one nonunicode,
I also have a version built with VC++ 6.
Any tips on how I can get output from the databse using the m_search_edit variable??