# Having problems getting data out from mysql

**URL:** <https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529>\
**Category:** General\
**Created:** [11 February 2020 01:31 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529 "2020-02-11T01:31:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zunder1990](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@zunder1990](https://discourse.nodered.org/u/zunder1990)\
**Post date:** [11 February 2020 01:31 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529/1 "2020-02-11T01:31:58Z")

</div>

I may trying to convert the array that I get from mysql to variable. Then array passes though my function node, the payload is unchanged ans still has the array as the payload.

Here is my function node

```auto
msg.FullName = msg.payload[0]['FullName'].toString();
return msg;

```

I have also tried this and no luck

```auto
msg.name = msg.payload[0].FullName.toString();

```

Here is the output from mysql with single match to mysql request. I would like it so that msg.FullName would be testfullname in this case.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/3929bc86251c076ba8332bfb219a70f20354e5ac.png)

I am also getting no errors.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [11 February 2020 06:09 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529/2 "2020-02-11T06:09:14Z")

</div>

You are assigning the converted value directly to the message object as `msg.FullName` or `msg.name`.  
If you want to see it in the `payload`, you have to assign it there. 🙂

So try something like

```auto
msg.payload = msg.payload[0]['FullName'].toString();

```

Also, I would add some plausibility checks for the input data. E.g. the array can be empty if there are no results, the string could be null, ...

Another suggestion: To improve readability in the debug bar remove the query from the message after you used it with `delete msg.topic;`

---

<div class="post-metadata">

**Author:** ![zunder1990](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@zunder1990](https://discourse.nodered.org/u/zunder1990)\
**Post date:** [11 February 2020 13:37 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529/3 "2020-02-11T13:37:39Z")

</div>

Thanks for the tip about delete msg.topic;

```auto
msg.payload = msg.payload[0]['FullName'].toString();

```

This did work but how do I get more than more var out?  
I have updated mysql request to pull all of the data that I want  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e5e03c42d4c34e61103a689ae9cfeeda7034dc8d.png)

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [11 February 2020 13:59 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529/4 "2020-02-11T13:59:26Z")

</div>

Normally you could just assign the result set to msg.payload, like

`msg.payload = msg.payload[0]` to get an object like `{FullName: 'testfullname', TalkTitle: '...'}`...

Those strings shouldn't be buffers in the first place, which data types are you using for these fields? That shouldn't happen with `varchar` or `char`, they should be normal strings.

If you want to keep it that way, you need to convert each one and assign them manually.

```auto
msg.payload = {
    FullName: msg.payload[0]['FullName'].toString(),
    TalkTitle: msg.payload[0]['TalkTitle'].toString()

}

```

...and so on.

---

<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:** [25 February 2020 13:59 UTC](https://discourse.nodered.org/t/having-problems-getting-data-out-from-mysql/21529/5 "2020-02-25T13:59:27Z")

</div>

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