| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Showing MySQL Rows in C++ using cout
I was trying to develop a program using Igal Reizman's tutorial as a base http://www.devarticles.com/c/a/Cplusplus/Building-a-Store-Application-With-MySQL-and-C/, but Visual C++ is crapping out when I try to display results of a row. I use 'cout <<' rather than the 'printf()' for output on demand from my lecturer. I'm wondering if this is the reason that the code doesn't work. Here is the portion of the code up to where it fails
#include <stdio.h> #include <mysql++.h> #include <iostream> using std::cout; using std::endl; #include <iomanip> #include <fstream> MYSQL *pConnection; // pointer the MYSQL structure MYSQL_RES *pResult; // pointer to the result set structure MYSQL_ROW Row; // row information int main(int argc, char* argv[]) { if (argc==2) cout << "Commencing Game: " << argv[1] << endl << endl; pConnection = mysql_init(NULL); if(!pConnection) return 0; cout << "Connecting to GMBA Database" << endl; if(mysql_real_connect(pConnection,"localhost","root","","GMBA",0,NULL,0) == NULL) return 0; cout << "Connected to GMBA Database" << endl; mysql_query(pConnection,"SELECT * FROM game WHERE Game_ID=1"); //query the database pResult = mysql_use_result(pConnection); while ((Row = mysql_fetch_row(pResult))); { cout << Row[0] << endl; } mysql_free_result(pResult); mysql_close(pConnection); cout << "Connection Terminated to GMBA Database" << endl; return 0; } The while loop which displays the result of Row[0] with cout is where the program dies (sending an error report to microsoft). Debugging shows the error to be at that line. Do you know where the error lies? |
|
#2
|
|||
|
|||
|
Doh, easy mistake....
I had a semicolon at the end of the while statement. All is well again in the world. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Showing MySQL Rows in C++ using cout |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|