Hola gran comunidad sin duda me han sido de gran ayuda a mi proyecto y tengo otra (y espero ultima ) duda con mi programación.
EL PROBLEMA ES que quiero leer los datos de mi base de datos usando la declaración SELECT obviamente, pero en los ejemplos que encontré en Internet solamente muestran los datos sin mas que hacerle a los mismos. Pero quiero que cada resultado que me de sea una variable que pueda utilizar para unas funciones especificas. AYUDA POR FAVOR
#include <WiFiManager.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
WiFiClient client;
MySQL_Connection conn((Client *)&client);
IPAddress server_addr(192, ---, -, --); // MySQL server IP ---------------DIRECCCION IPv4
char user[] = "*********"; // MySQL user
char password[] = "******"; // MySQL password
void setup() {
Serial.begin(9600);
WiFiManager wifiManager;
wifiManager.autoConnect("AutoConnectAP");
Serial.println("connected...yeey :)");
Serial.println("Connecting to database");
while (conn.connect(server_addr, 3306, user, password) != true) {
delay(200);
Serial.print ( "." );
}
Serial.println("");
Serial.println("Connected to SQL Server!");
}
void loop() {
const char QUERY_POP[] = "SELECT Capacidad FROM *****.***** where Capacidad >=100";
char query[128];
//------------------------------------------^^^^^^^^AQUI ARRIBA ES LA DECLARACIÓN QUE HAGO
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
sprintf(query, QUERY_POP, 9000000);
// Execute the query
cur_mem->execute(query);
// Fetch the columns and print them
column_names *cols = cur_mem->get_columns();
for (int f = 0; f < cols->num_fields; f++) {
Serial.print(cols->fields[f]->name);
if (f < cols->num_fields-1) {
Serial.print(',');
}
}
Serial.println();
// Read the rows and print them
row_values *row = NULL;
do {
row = cur_mem->get_next_row();
if (row != NULL) {
for (int f = 0; f < cols->num_fields; f++) {
Serial.print(row->values[f]);
if (f < cols->num_fields-1) {
Serial.print(',');
}
}
Serial.println();
}
} while (row != NULL);
// Deleting the cursor also frees up memory used
delete cur_mem;
}