# Connection with database error

**URL:** <https://discourse.nodered.org/t/connection-with-database-error/30172>\
**Category:** General\
**Created:** [16 July 2020 06:36 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172 "2020-07-16T06:36:54Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 09:41 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/22 "2020-07-17T09:41:29Z")

</div>

@Colin yes ,i am using mysql ,and please one request to this node red community please i want help so please remove this limitation of query in one day.  
Thank you

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 09:43 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/23 "2020-07-17T09:43:45Z")

</div>

If it won't let you post again then you can edit your previous post (use the pen icon).  
What exactly is the part that you don't know how to do? I don't mean a general description of the complete task, but _exactly_ which bit isn't working?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 09:54 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/24 "2020-07-17T09:54:38Z")

</div>

ok.i have created rfid table in mysql where rfidno,email etc is stored.I have connected my database with my mqtt rfid code .Now I want to know how can i validate/verify/check that whether my mqtt rfidno typed y some employee is in our database table or not .

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 09:56 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/25 "2020-07-17T09:56:36Z")

</div>

Have you got the entered rfid into node-red?  
If so then presumably you need to run a query on the database to find the matching record, if it exists.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:00 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/26 "2020-07-17T10:00:14Z")

</div>

Yes I have connected rfid node with node red ?Now i dont know how to write sql query to match record.I am attaching screenshots for more clarifications.In Database i have E1234561 so success i want to show it is also showing,but when i entered wrong rfid like E1234565 it is again showing success,i want fail there  
 ![p1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89576aa944969cab3eea3b94f6f30f499af3253b.png) ![p2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9d31eb5453280d141d7ccc0685f17c78981deca.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:03 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/27 "2020-07-17T10:03:21Z")

</div>

What query are you trying to run? Get it working in the mysql command line client (or another client) first, then you can put that query into node red.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:05 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/28 "2020-07-17T10:05:47Z")

</div>

As i am new to node red and sql ,so i tried this query please check and give suggestion where i have written wrong

msg.topic="SELECT rfidno FROM rfid1 WHERE rfidno='E1234561'";  
if(msg.topic!='E1234562')  
msg.topic="select 'CR\_SUCCESS' as ' '";  
else  
msg.topic="select 'CR\_FAIL' as ' ' ";  
return msg;

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 July 2020 10:06 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/29 "2020-07-17T10:06:10Z")

</div>

1 - Put seperate `debug` nodes on the `function` and the output of the `MySQL` node (set both `debug` nodes to display the 'Complete msg object'  
2 - Please paste in a copy of the table's schema  
3 - Please export your flow and insert it in a reply.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:09 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/30 "2020-07-17T10:09:03Z")

</div>

Having constructed msg.topic with the select query you have to send that message, so in the function node you want something like

```auto
msg.topic="SELECT rfidno FROM rfid1 WHERE rfidno='E1234561'";
return msg

```

Then you feed that into the sql node and it should give you an array of length 1 if it finds it or an empty array if it doesn't.  
[Edit] not sure about SQL in mysql but I think you might need quotes or something round table and field names. As I said, check the query works in the command line client first, then you will know that any other problems are node-red related.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:13 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/31 "2020-07-17T10:13:06Z")

</div>

see like this , sorry for my mistake if any  
 ![p3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3955cac0cba5128d2228ce77a9ea24b330d1388.png) ![p4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a86e0b279f542b8704b7e2191e883d64004c849.png)

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:13 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/32 "2020-07-17T10:13:58Z")

</div>

> [@Colin](#):
>
> As I said, check the query works in the command line client first, then you will know that any other problems are node-red related.

not getting this,sorry please could you explain more

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 July 2020 10:15 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/33 "2020-07-17T10:15:56Z")

</div>

Please only one wire to a debug node so you don't get duplicate information - also you should name the debug nodes so you can see which one displays information in the debug log.

what about the other two items I asked you about?

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:18 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/34 "2020-07-17T10:18:39Z")

</div>

> [@zenofmud](#):
>
> Please paste in a copy of the table's schema
> 
> > [@zenofmud](#):
> >
> > Please export your flow and insert it in a reply.

Now getting this ?what you mean?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:20 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/35 "2020-07-17T10:20:35Z")

</div>

> [@shipra](#):
>
> not getting this,sorry please could you explain more

Whatever tool you used for writing the data to the database will probably also allow you to run queries, test your query using that tool. Then you will know the query works.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:23 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/36 "2020-07-17T10:23:02Z")

</div>

See like this you are saying

![w](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8bbe057fba695fe2277c4c17838f184aea663ea2.png) ![w1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f34af61474b8cd35c84b63bb1a2bd9daadcb0fa0.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:23 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/37 "2020-07-17T10:23:58Z")

</div>

That appears to be working perfectly.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:24 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/38 "2020-07-17T10:24:27Z")

</div>

ok you mean like phpMyAdmin tool

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:24 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/39 "2020-07-17T10:24:50Z")

</div>

You don't need to bother now as you can see your flow is working.

---

<div class="post-metadata">

**Author:** ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)\
**Post date:** [17 July 2020 10:25 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/40 "2020-07-17T10:25:47Z")

</div>

No but i want FAIL messages or SUCCESS message so that i can transfer this string to my mqtt subscriber

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2020 10:26 UTC](https://discourse.nodered.org/t/connection-with-database-error/30172/41 "2020-07-17T10:26:16Z")

</div>

What do you get if you feed in an invalid id?

[Previous page](https://discourse.nodered.org/t/connection-with-database-error/30172.md?page=1)

[Next page](https://discourse.nodered.org/t/connection-with-database-error/30172.md?page=3)
