MySQL Forums
Forum List  »  Connector/Arduino

Trouble Getting mysql connection.
Posted by: Aaron Ang
Date: August 12, 2015 04:24AM

So I've been trying to use the connected and I've used ipconfig to get my IP address of my database and i've entered the following code to try and push a simple "hello" onto my database but I keep getting the message

Connecting...
Connection failed.

Here's my current code.

/**
* Example: Insert Example: Hello, MySQL!
*
* This code module demonstrates how to create a simple
* database-enabled sketch with inserting data.
*/
#include "SPI.h"
#include "Ethernet.h"
#include "sha1.h"
#include "mysql.h"
/* Setup for Ethernet Library */
byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x3A, 0xDC };
IPAddress server_addr(192,168,1,240);
/* Setup for the Connector/Arduino */
Connector my_conn; // The Connector/Arduino reference
char user[] = "ang";
char password[] = "";//myset password
char INSERT_SQL[] =
"INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";
void setup() {
Ethernet.begin(mac_addr);
Serial.begin(115200);
while (!Serial);
delay(1000);
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)){
Serial.println("Connected!");
my_conn.cmd_query(INSERT_SQL);
Serial.println("Data inserted.");
} else {
Serial.println("Connection failed.");
}
}
void loop() {
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Trouble Getting mysql connection.
2981
August 12, 2015 04:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.