Node red value to mysql

Hi all,

Now i tried to send data from node red to mysql but if i have single value it is ok but if more than 2 values how i wirte script in function node

Here is my current flow

Speed1 = msg.payload.Value_Speed_1_SB5_Recir;
Speed2 = msg.payload.Value_Speed_2_SB5_Recir
PV = msg.payload.Value_PV_SB5_Recir;
msg.topic = "INSERT INTO mysql ('value_SB5_Recir_Speed1`, 'value_SB5_Recir_Speed2', 'value_SB5_Recir_PV') VALUES ('"+Speed1+"', '"+Speed2+"', '"+PV+"');"
return msg;

[{"id":"44997861.54cde8","type":"function","z":"72a03a1a.19aa14","name":"Function send to mysql","func":"Speed1 = msg.payload.Value_Speed_1_SB5_Recir;\n////Speed2 = msg.payload.Value_Speed_2_SB5_Recir\n//PV = msg.payload.Value_PV_SB5_Recir;\nmsg.topic = \"INSERT INTO mysql (`value_SB5_Recir_Speed1`) VALUES ('\"+msg.payload+\"');\"\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":60,"wires":[["22d409d2.9973d6"]]}]

Please help me for send data to table at mysql

Hi, first, please edit your post and surround the code and the flow with three backticks

code here

flow here

Secondly - you have only sent a function node (not a flow) - so it is quite difficult to help you without understanding where the data comes from. i have my suspicion that the values come from separate nodes & you'll need a join - but I am only speculating due to lack of info.

a screenshot of your flow & a description of its purpose would also help others.

1 Like

I find it much easier to use the template node when creating an sql statement if the data is all in the msg object. Here is an example

note for text you need the double quotes around the item.


The values come from PLC siemens S7-300

Flow as below
[{"id":"44997861.54cde8","type":"function","z":"72a03a1a.19aa14","name":"Function send to mysql","func":"Speed1 = msg.payload.Recir_SB5_speed1;\nSpeed2 = msg.payload.Recir_SB5_speed2;\nPV = msg.payload.Recir_SB5_PV;\nmsg.topic = "INSERT INTO mysql (value_SB5_Recir_Speed1, value_SB5_Recir_Speed2, value_SB5_Recir_PV) VALUES('"+msg.payload.Recir_SB5_speed1 +"', '"+msg.payload.Recir_SB5_speed2 +"', '"+msg.payload +"');"\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":180,"wires":[["22d409d2.9973d6","87ed3551.a65c68"]]}]

e q w

If i use template node no need function node right ?

Excellent info.

Firstly though, in order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - How to share code or flow json

Secondly, you don't have debug before the function. It is impossible to see what is going on to your function.

And again, your flow export is only the function. When exporting, select all nodes you wish to export before opening the export dialog.

Lastly, my suspicion was correct...

Watch this 4m video to understand what I mean.

Correct, BUT as @Steve-Mcl said, you do need to add a join since you have three seperate messages.

One last thing, when uploading images please make them bigger. Your images are so small that I can not read any of the text.

thank now done already i use global.get for this case

?? How?? How are you making sure that you get the data from all three inputs? What are the input nodes anyway? You never provided your entire flow and the image is too small to make out.

If you have solved yout issue, you should fully explain what you did in case someone else reads this in the future while tring to solve an issue of their own.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.