# How To get Variable name as value then store in in mysql dataabse

**URL:** <https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229>\
**Category:** General\
**Created:** [10 July 2021 04:27 UTC](https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229 "2021-07-10T04:27:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![muhammad\_mikail\_j](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@muhammad\_mikail\_j](https://discourse.nodered.org/u/muhammad_mikail_j)\
**Post date:** [10 July 2021 04:27 UTC](https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229/1 "2021-07-10T04:27:18Z")

</div>

Hi All,

Nice to connect with people in this forum.  
I would like to make data logger with flow below,  
PLC (Data source) -\> Node-Red -\> MySql database.

I have store value to database with function below :  
msg.topic = "INSERT INTO inject\_testing (HOD\_Ozone) VALUES (" + msg.payload.HOD\_Ozone + ");";  
return msg;

The next purpose is to get variable name as value and store it in database, for example the variable name is "HOD\_Ozone" then I need to get "HOD\_Ozone" store it in other variable to be able store in db.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2ffbaafc641aaa860afc4a2bbe6be96b0a668fe.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5007584bd60f5fca446e39225315a916f7bf49a9.png)

Anyone have experience in this case ?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 July 2021 08:28 UTC](https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229/2 "2021-07-10T08:28:19Z")

</div>

You can use [object.entries()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) to get the key value pairs of an object.

---

<div class="post-metadata">

**Author:** ![muhammad\_mikail\_j](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@muhammad\_mikail\_j](https://discourse.nodered.org/u/muhammad_mikail_j)\
**Post date:** [14 July 2021 05:36 UTC](https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229/3 "2021-07-14T05:36:55Z")

</div>

Thank you @E1cid for your feedback, I will try it first

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 September 2021 05:37 UTC](https://discourse.nodered.org/t/how-to-get-variable-name-as-value-then-store-in-in-mysql-dataabse/48229/4 "2021-09-12T05:37:16Z")

</div>

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