ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
333 stars 133 forks source link

Update data with dynamic value ESP8266 #139

Closed oussama415 closed 2 years ago

oussama415 commented 4 years ago

Hi, Please i want to update data from a database table with a dynamic value I have an incrementing variable and I want to update this value in the database each time

I tried :

int counter ;
char UPDATE_SQL[] = "UPDATE database.table SET counter = %f WHERE id= 1";
char query2[500];

// loop()
   counter = 20;
    sprintf(query2, UPDATE_SQL, counter);
    Serial.println("Updating data energy.");
    Serial.println(query2);
    MySQL_Cursor *cur_mem7 = new MySQL_Cursor(&conn);
    cur_mem7->execute(query2);
    delete cur_mem7;

I have always 0 In value !!

I need your help Thanks.

ChuckBell commented 4 years ago

Use %d or %i, not %f. See sprintf docs.

On Wed, May 20, 2020 at 10:52 oussama415 notifications@github.com wrote:

Hi, Please i want to update data from a database table with a dynamic value I have an incrementing variable and I want to update this value in the database each time

I tried :

int counter ; char UPDATE_SQL[] = "UPDATE u255900507_nrsolar.modbus_mono_clients SET counter = %f WHERE id= 1"; char query2[500];

// loop() counter = 20; sprintf(query2, UPDATE_SQL, counter); Serial.println("Updating data energy."); Serial.println(query2); MySQL_Cursor *cur_mem7 = new MySQL_Cursor(&conn); cur_mem7->execute(query2); delete cur_mem7;

I have always 0 In value !!

I need your help Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYCTBUPYCWKLLQQWTXLRSPVBTANCNFSM4NGAG6BA .

oussama415 commented 4 years ago

Thanks so Much, it work with %d Thanks.

ChuckBell commented 2 years ago

Closed due to inactivity. Please open a new ticket if this is still relevant.