How to pass a MYSQL connection pointer from header file to main program?
Hello! I am new to the C++ & mySQL world so this might be a silly question, but I have a ANSI C\C++ program (in DEV_C++) and I have the mySQL database connection separate from the main code itself. So I have a header file which manages the mySQL connection and returns a MYSQL* connection value.
When I try using the connection returned on the main program the program fails.
The value returned is not NULL so I don't know what my problem could be.
Any suggestions?
Thank you so much for your help!
EM
PS: Heres an example of my code :
HEADER FILE:
MYSQL* getConnection(){
char *server = "server";
char *user = "user";
char *password ="password";
char *database = "database";
MYSQL *conn,*mysql;
mysql_init(&mysql);
conn = mysql_real_connect(&mysql,host,user,pass,db,0,NULL,0);
return conn;
}
MAIN.CPP
#include "header"
int main{
MYSQL *conn;
int query_state;
char query[300];
int record;
conn = getConnection();
sprintf(query,"SELECT * FROM TABLE WHERE RECORD_ID = %d",record);
query_state = mysql_query(conn,query);
.
.
.
}
Subject
Views
Written By
Posted
How to pass a MYSQL connection pointer from header file to main program?
1175
August 20, 2010 09:07AM
493
August 27, 2010 09:55AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.