Archived

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

WebsiteWill

ARGHHHH MYSQL++

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_real_connect(conn,host,username,password,database,0,NULL,0); 
	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"); 
	   } 
	} 
	mysql_close(conn); 
	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


mysql_real_connect(conn,"localhost","db_username","db_password","db",0,NULL,0);


or even


char host[] = "localhost";
char username[] = "db_username";
char password[] = "db_passwd";
char database[] = "db";
mysql_real_connect(conn,host,username,password,database,0,NULL,0);

Share this post


Link to post
Share on other sites