C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2004, 12:20 AM
MartyConlonJr MartyConlonJr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 14 MartyConlonJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 52 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old July 22nd, 2004, 01:16 AM
MartyConlonJr MartyConlonJr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 14 MartyConlonJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 52 sec
Reputation Power: 0
Doh, easy mistake....

I had a semicolon at the end of the while statement.

All is well again in the world.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Showing MySQL Rows in C++ using cout


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway