I want to retrieve data from database using sim808. I saw mysql connector library while I was searching. But in all examples, this library are using with ethernet shield. Can I use this library for sim808? Is there a way?
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
byte mac_addr = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(10,0,1,35); // IP of the MySQL server here
char user = “root”; // MySQL user login username
char password = “secret”; // MySQL user login password
// Sample query
char query = “SELECT * FROM world.city LIMIT 12”;
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println(“Connecting…”);
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println(“Connection failed.”);
}
void loop() {
delay(2000);
Serial.println("\nRunning SELECT and printing results\n");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// 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;
}