I made a server that uses MySQL as database and I guess that it wouldn't be good to connect again, and again, and again whenever I need to get data. The main-function uses threads to "split up" whenever it gets a connection but I thought it would be best to have only one connection to the database throughout the whole server.
So that's why the connection should be directly when the server starts up and the connection would be closed when the server dies.
Here is how I connects to the server:
Code:
mysqlcppapi::Connection con;
con.set_Host("127.0.0.1");
con.set_User("root");
con.connect();
con.select_database("operation_m");
After this I use the "con" variable to create a query and execute the query and so on. So all other files (C++ source code files) just need the variable "con".
How should I design main to make the variable able to all the other files that need to access the database?