Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

C++ mySQL connection failed (15 replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>