I am trying to fetch data from the MySQL database using the MySQL Connector library. But the program isn't returning any data from the database. Please any suggestions? I have data in the MySQL database. I attached a picture of the Serial monitor output.
int device_id = 1;
String Parameter[3] = {"one", "two", "three"};
EthernetClient client;
MySQL_Connection conn((Client *)&client);
const char QUERY_PARA[] = "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id= %lu;";
char query[128];
void setup()
{
Serial.begin(115200);
while (!Serial);
Ethernet.begin(mac_addr);
}
void loop()
{
Serial.println("inside the loop....");
delay(10000);
check_parameter();
}
void check_parameter()
{
if (conn.connect(server_addr, 3306, user, password))
{
Serial.println("calling the check_para....");
delay(5000);
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
sprintf(query, QUERY_PARA, device_id);
cur_mem->execute(query);
column_names *cols = cur_mem->get_columns();
Serial.println();
row_values *row = NULL;
do
{
row = cur_mem->get_next_row();
if (row != NULL)
{
// here is the problem. row is always NULL! I dunno why ??????
Parameter[0] = String(row->values[0]);
Parameter[1] = String(row->values[1]);
Parameter[2] = String(row->values[2]);
cur_mem->free_row_buffer();
}
} while (row != NULL);
cur_mem->free_columns_buffer();
delete cur_mem;
Serial.println("printing parameters");
Serial.println(Parameter[0]);
Serial.println(Parameter[1]);
Serial.println(Parameter[2]);
conn.close();
}
else
{
Serial.println("Connection failed.");
}
}
