Hi Guys,
Been fighting with the mysql client from the cookbook for the last couple of days.
I have tried using the example but doesnt appear to work for me.
below is the code i am using, I am using mysql v5.1
#include "mbed.h"
#include "EthernetNetIf.h"
#include "MySQLClient.h"
#define SQL_SERVER "192.168.0.1"
#define SQL_USER "root"
#define SQL_PASSWORD "f4irl4dy"
#define SQL_DB "test"
EthernetNetIf eth(
IpAddr(192,168,0,101), //IP Address
IpAddr(255,255,255,0), //Network Mask
IpAddr(192,168,0,1), //Gateway
IpAddr(192,168,0,1) //DNS
);
MySQLClient sql;
MySQLResult sqlLastResult;
void onMySQLResult(MySQLResult r)
{
sqlLastResult = r;
}
int main()
{
printf("Start\n");
printf("Setting up...\n");
EthernetErr ethErr = eth.setup();
if(ethErr)
{
printf("Error %d in setup.\n", ethErr);
return -1;
}
printf("Setup OK\n");
Host host(IpAddr(), 3306, SQL_SERVER);
printf("host");
//Connect
sqlLastResult = sql.open(host, SQL_USER, SQL_PASSWORD, SQL_DB, onMySQLResult);
printf("mysql processing");
while(sqlLastResult == MYSQL_PROCESSING)
{
Net::poll();
}
if(sqlLastResult != MYSQL_OK)
{
printf("Error %d during connection\n", sqlLastResult);
}
//SQL Command
//Make command
char cmd[128];
printf("done char cmd");
//const char* msg="Hello World!";
sprintf(cmd, "INSERT INTO test.Test (Test) VALUES ('sdfsdf');");
printf("done sprintf");
printf("%s", cmd);
//INSERT INTO DB
string cmdStr = string(cmd);
sqlLastResult = sql.sql(cmdStr);
printf("done cmd string");
printf("mysql processing");
while(sqlLastResult == MYSQL_PROCESSING)
{
Net::poll();
}
if(sqlLastResult != MYSQL_OK)
{
printf("Error %d during SQL Command\n", sqlLastResult);
}
sql.exit();
while(1)
{
}
return 0;
}
I get an Error 7 during sql command, not quite sure what this means but I think its saying that when it sends this
"INSERT INTO test.Test (Test) VALUES ('sdfsdf');"
to the mysql server it doesn't like it, however I have tried using the command line utility for mysql enter the exact same line except for changing the sdfsdf to different charactors and it gets accepted no problem, I know this command is a different format from the cookbook version but that doesnt work either and if i try entering that line on the command line utility the mysql server says I have a syntax error.
Not sure whats going wrong would really appreciate any help, thanks.
Hi Guys,
Been fighting with the mysql client from the cookbook for the last couple of days.
I have tried using the example but doesnt appear to work for me.
below is the code i am using, I am using mysql v5.1
#include "mbed.h" #include "EthernetNetIf.h" #include "MySQLClient.h" #define SQL_SERVER "192.168.0.1" #define SQL_USER "root" #define SQL_PASSWORD "f4irl4dy" #define SQL_DB "test" EthernetNetIf eth( IpAddr(192,168,0,101), //IP Address IpAddr(255,255,255,0), //Network Mask IpAddr(192,168,0,1), //Gateway IpAddr(192,168,0,1) //DNS ); MySQLClient sql; MySQLResult sqlLastResult; void onMySQLResult(MySQLResult r) { sqlLastResult = r; } int main() { printf("Start\n"); printf("Setting up...\n"); EthernetErr ethErr = eth.setup(); if(ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("Setup OK\n"); Host host(IpAddr(), 3306, SQL_SERVER); printf("host"); //Connect sqlLastResult = sql.open(host, SQL_USER, SQL_PASSWORD, SQL_DB, onMySQLResult); printf("mysql processing"); while(sqlLastResult == MYSQL_PROCESSING) { Net::poll(); } if(sqlLastResult != MYSQL_OK) { printf("Error %d during connection\n", sqlLastResult); } //SQL Command //Make command char cmd[128]; printf("done char cmd"); //const char* msg="Hello World!"; sprintf(cmd, "INSERT INTO test.Test (Test) VALUES ('sdfsdf');"); printf("done sprintf"); printf("%s", cmd); //INSERT INTO DB string cmdStr = string(cmd); sqlLastResult = sql.sql(cmdStr); printf("done cmd string"); printf("mysql processing"); while(sqlLastResult == MYSQL_PROCESSING) { Net::poll(); } if(sqlLastResult != MYSQL_OK) { printf("Error %d during SQL Command\n", sqlLastResult); } sql.exit(); while(1) { } return 0; }
I get an Error 7 during sql command, not quite sure what this means but I think its saying that when it sends this
to the mysql server it doesn't like it, however I have tried using the command line utility for mysql enter the exact same line except for changing the sdfsdf to different charactors and it gets accepted no problem, I know this command is a different format from the cookbook version but that doesnt work either and if i try entering that line on the command line utility the mysql server says I have a syntax error.
Not sure whats going wrong would really appreciate any help, thanks.