9 years, 10 months ago.

Mysql client help

I am trying to set up a SQL client, https://mbed.org/cookbook/MySQL-Client. What I have so far is the following, however I get "Error 9 during connection" and "Error 3 during SQL Command", ANyone knows how to solve this? My database is called database, table -> ecgvalues, column -> values

#include "mbed.h"
#include "EthernetNetIf.h"
#include "MySQLClient.h"

#define SQL_SERVER   "127.0.0.1"
#define SQL_USER     "root"
#define SQL_PASSWORD "ecg"
#define SQL_DB       "database"

EthernetNetIf eth(
  IpAddr(192,168,2,12), //IP Address
  IpAddr(255,255,255,0), //Network Mask
  IpAddr(192,168,2,1), //Gateway
  IpAddr(192,168,2,1)  //DNS
); 
MySQLClient sql;

AnalogIn Ain(p20);
float data_in;

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);
  
  //Connect
  sqlLastResult = sql.open(host, SQL_USER, SQL_PASSWORD, SQL_DB, onMySQLResult);
  while(sqlLastResult == MYSQL_PROCESSING)
  {
    Net::poll();
  }
  if(sqlLastResult != MYSQL_OK)
  {
    printf("Error %d during connection\n", sqlLastResult);
  }
  
  //SQL Command
  //Make command
  char cmd[128] = {0};
  data_in = Ain;
  sprintf(cmd, "INSERT INTO ecgvalues (values) VALUES('%f')", data_in);
  
  //INSERT INTO DB
  string cmdStr = string(cmd); 
  sqlLastResult = sql.sql(cmdStr);
  while(sqlLastResult == MYSQL_PROCESSING)
  {
    Net::poll();
  }
  if(sqlLastResult != MYSQL_OK)
  {
    printf("Error %d during SQL Command\n", sqlLastResult);
  }
  
  sql.exit();
  
  while(1)
  {
  
  }
  
  return 0;
}

hi

I have this same problem Error 9 during connection" and "Error 3 during SQL Command Solve the problem? Please help

posted by Balázs Kocsi 12 Mar 2015

Sorry never solved the problem

posted by Johann Hur 12 Mar 2015

1 Answer

7 years, 8 months ago.

Hi

Have you come far?

Your first problem is that your sql server does not have the IP address 127.0.0.1, but it is on a different IP address: 192.168.2.xxx

I'm not super into English so use google translate, sorry