Thread: Help w/ mysql++ function

  1. #1
    Registered User
    Join Date
    Nov 2003

    Help w/ mysql++ function

    Hello -

    This is my first remotely useful win32 app and I'm having some issues...

    The program simply connects to a MySQL database and displays the results in a ListBox. However, the function I am using to do this is crashing the program at run-time.

    int DoMysqlStuff(HWND hwndDlg)
    	const char* host = "localhost";
    	const char* username = "xp";
    	const char* password = "*****";
    	const char* database = "nazgul_db";
    	MYSQL *conn;
    	conn = mysql_init(NULL); 
    	if(mysql_real_connect(conn, host, username, password, 
    		database, 0, NULL, 0)) {
    		const char *success = "Connected!";
    		SendDlgItemMessage(hwndDlg, IDC_LISTDB, LB_ADDSTRING, 0, (LPARAM) success);
    	// create vars to get a result and a row pointer from DB 
    	MYSQL_RES *result_set; 
    	MYSQL_ROW row; 
    	unsigned int i; 
    	mysql_query(conn, "SELECT id,name,level FROM guild_members"); 
    	result_set = mysql_store_result(conn); 
    	if (!result_set) { 
    		MessageBox(NULL, "Error storing result\n", "Error", MB_OK); 
    		return -1; 
    	// find out how many rows there will be 
    	unsigned int numrows = mysql_num_rows(result_set); 
    	while ((row = mysql_fetch_row(result_set)) != NULL) { 
    		SendDlgItemMessage(hwndDlg, IDC_LISTDB, LB_ADDSTRING, 0, (LPARAM)(row[i] != NULL ? row[i] : "NULL"));
    	return 0;
    I think the error is somewhere in the while() loop - I really don't know what it is though?

    Any help would be appreciated,

    Thank you

    - rednax

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Where is the value of i set? Most compilers should give you a warning.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global mySQL connection function
    By redixe in forum C++ Programming
    Replies: 13
    Last Post: 10-28-2008, 07:02 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM