Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 5407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone familiar with MySQL++ that can lend a hand? Presumably this code is supposed to work.
#include <stdio.h> 
#include <mysql++.h> 

#define host "localhost" 
#define username "db_username" 
#define password "db_password" 
#define database "db"

MYSQL *conn;
int main() 
	conn = mysql_init(NULL); 
	MYSQL_RES *res_set; 
	MYSQL_ROW row; 
	unsigned int i; 

	mysql_query(conn,"SELECT * FROM users WHERE userid=1"); 
	res_set = mysql_store_result(conn); 
	unsigned int numrows = mysql_num_rows(res_set); 
	while ((row = mysql_fetch_row(res_set)) != NULL) 
	for (i=0; i<mysql_num_fields(res_set); i++) 
	printf("%s\n",row[i] != NULL ? row[i] : "NULL"); 
	return 0; 
However, if I alter ANY of the #defines to reflect the info I need to access my database then it gives compile errors. error C2143: syntax error : missing ')' before 'string' error C2143: syntax error : missing ';' before 'string' fatal error C1004: unexpected end of file found It makes no sense. If I change to line #define database "db" to #define database "dc" I get those errors. The more of those lines I change the more errors I get. <throws his hands into the air> Thanks for any help, Webby[/source] [edited by - websitewill on September 2, 2003 8:06:57 PM]

Share this post

Link to post
Share on other sites
I can''t help with what''s causing the problem, but I can tell you that''s a terrible use of #defines.

Why don''t you just use the values directly in


or even

char host[] = "localhost";
char username[] = "db_username";
char password[] = "db_passwd";
char database[] = "db";

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!