Hi guys. I want to send arduino analog pin data to mysql server, but it gives the following error:
Error: 163 = You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '')')')' at line 1.
can someone help me ? here the project sketch:
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#define ANALOG_PIN_1 1
int val;
byte mac_addr[] = { 0xFE, 0xBD, 0xCD, 0xCB, 0xA8, 0xAA };
IPAddress server_addr(10, 5, 51, 13); // IP of the MySQL *server* here
char user[] = "arduino"; // MySQL user login username
char password[] = "12345678"; // MySQL user login password
// Sample query
char INSERT_SQL[] = "INSERT INTO hello.test (message) VALUES ('%s')";
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(1000);
val = analogRead(ANALOG_PIN_1);
char query[80];
sprintf(query, INSERT_SQL, val);
Serial.println("Recording data.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
cur_mem->execute(INSERT_SQL);
// Note: since there are no results, we do not need to read any data
// Deleting the cursor also frees up memory used
delete cur_mem;
}
and sql script:
CREATE DATABASE hello;
CREATE TABLE hello.test (
num integer primary key auto_increment,
message char(40),
recorded timestamp
);


