Hi,
I'm wanting to start a database connection at the start of an app and keep it open for all methods and classes that I'm #including in my project.
First I went about it by creating the connection in the Main source file outside of any class declarations and then declaring it external in other source files.
This works ok within the same source file and although it compiles, the connection is not open in any function defined outside the file (in another source file).
Second method I tried was to pass the mysql::Connecti on * conn as a parameter: // Call MyFn from a method in Main source file:
MyFn(this, &conn);
connection appears alive but but the app crashes when I execute the query:
Can anyone help me please ?
I'm wanting to start a database connection at the start of an app and keep it open for all methods and classes that I'm #including in my project.
First I went about it by creating the connection in the Main source file outside of any class declarations and then declaring it external in other source files.
Code:
// Main cpp file
#include <mysql++>
mysql::Connection * conn;
// Class definitions follow, I open the connection in Main()
if (!(conn.connect("dbName", "localhost", "user", "pwd"))) {
...
Second method I tried was to pass the mysql::Connecti on * conn as a parameter: // Call MyFn from a method in Main source file:
MyFn(this, &conn);
connection appears alive but but the app crashes when I execute the query:
Code:
// Function def in Another source file
void myFn(wxFrame *frame, Connection *conn)
{
mysqlpp::Query query = conn.query(); <--- THIS is probably the cause !?
// set up query code...
// execute
mysqlpp::StoreQueryResult res = query.store(); // <--- Exception happens here
Comment