Please feel free to move this if you feel there is a more appropriate sub.
I've migrated my project to the NodeMCU(ESP8266) and am successfully selecting from, updating, and appending to a MySQL database by means of Chuck Bell's library.
I'm curious if there are 'proper' chunks of code I can use as an example to base my functions off of.
ie:
to append a record to a table, I'm using something like this:
void sendRecord(String statement) {
statement.toCharArray(INSERT_SQL, 300);
bool recordSent = false;
int connectFailed = 0;
while (!recordSent) {
if (conn.connect(server_addr, 3306, user, password)) {
delay(500);
cursor->execute(INSERT_SQL);
conn.close();
digitalWrite(D3, LOW);
for (int i = 0; i < sizeof(INSERT_SQL); i++) {
INSERT_SQL[i] = (char)0;
}
recordSent = true;
} else {
connectFailed++;
}
if (connectFailed > 10) {
statusIndicateMySQL_not_connected();
}
}
}
This code regularly results in failure to connect, hence the while(!recordSent)
I haven't been able to find concrete examples that properly explain WHEN to close a connection object, or WHEN to destroy a cursor.
Also, the time delay that should be used between establishing a connection to the MySQL server and executing the INSERT statement.
Lots of little details like this are damaging the reliability of my code.
What is the most Proper way to manipulate a MySQL database from this MCU?