MySQL Forums
Forum List  »  Connector/C++

C++ mySQL connection failed
Posted by: Philipp Mitterrutzner
Date: August 19, 2021 02:03AM

I have created a VST plugin with JUCE. I have created a database that asks whether a serial number is available.

After the user has logged in, he can log out. However, you have to log out after a few seconds, otherwise the connection gives me an error. If I wait longer than 5 seconds and click log out, nothing happens. I found out that this was created incorrectly at mysql_real_connect. No values ​​are read.

CODE:
int SQLLogout() {
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
char* key;
conn = mysql_init(0);

int ID;
std::ifstream infile("ID.txt");
infile >> ID;
infile.close();
mysql_real_connect(conn, "localhost", "root", "", "eq", 3306, NULL, 0); //this line is the problem

if (conn) {


std::ostringstream str;
str << "SELECT * FROM users WHERE UserID=" << ID;
std::string sql = str.str();

qstate = mysql_query(conn, sql.c_str());
if (!qstate) {
res = mysql_store_result(conn);
if (res->row_count == 0) {
return 0;
}
while (row = mysql_fetch_row(res)) {
if (atoi(row[0]) == ID) {

std::ostringstream str;
str << "UPDATE users SET Aktiv=0 WHERE (UserID=" << ID << ");";
std::string sql = str.str();

mysql_query(conn, sql.c_str());

std::ofstream outfile;
outfile.open("ID.txt"/*, std::ofstream::out | std::ofstream::trunc */ );
outfile << "0";
outfile.close();


WinExec("EQ.exe", 42);
std::quick_exit(42);
return 1;
}
}
}
else {
return 2;
}
}
else {
return 3;
}
}


CODE:
Logout.onClick = [this] {Logout.setClickingTogglesState(true); };
if (Logout.getClickingTogglesState() == true) {
SQLLogout();
}
the same is as soon as I enter the serial number, if I wait longer and in the meantime enter the serial number and this confirms an SQL error. The data were not read from mysql_real_connect

Does anyone know how I can solve this? Thanks in advance

Options: ReplyQuote


Subject
Views
Written By
Posted
C++ mySQL connection failed
1455
August 19, 2021 02:03AM
399
August 19, 2021 11:45AM
434
August 19, 2021 03:00PM
372
August 19, 2021 03:51PM
323
August 19, 2021 05:42PM
321
August 20, 2021 08:00AM
343
August 20, 2021 10:42AM
395
August 20, 2021 11:43AM
503
August 20, 2021 01:28PM


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.