首页 > 解决方案 > 如何根据 comming 链接更改数据库值

问题描述

我不知道该怎么说,但我会尝试:)

我正在使用 NodeMCU 和 CAM 模块,CAM 模块读取 QR 码,用户 1 获得如下链接:sitename.com/project/userid1

例如,另一个用户 2 有 sitename.com/project/userid2 链接。并且 CAM 模块通过字符串发送链接到我执行此步骤的 NODEMCU。

NODEMCU 可以将此链接连接到互联网。主要问题是我该怎么做:

当用户从特定地址登录时,例如用户 1 获取 sitename.com/project/userid1 链接。如何减少user1的余额(在数据库中定义)?因此,我可以使用来自任何链接的信息在数据库中进行交易。该站点如何知道我是如何来自该链接的?

请帮我。

编辑 1

我决定只为用户发送 ID,对于 userid1 发送到 1,userid2 发送到 2 ...当我得到“1”时,我想去 ID=1 用户并获得 user1 的余额。

所以,这是个新问题。当我将 nodemcu 连接到 MYSQL 时,如何获取余额值(这是表用户的成员)以及如何将 balance=balance-1 值发送到 MYSQL ?

如何将此代码添加到arduino

 UPDATE users SET balance=balance_new WHERE id = readx

readx come 1,2,3,.. to the CAM module
users name the mysql table 
balance is the member of the users

这是我的一些代码:(如何添加部分mysql获取值和发送值)

#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
int balance;

const char* ssid = "ssid";
const char* password = "pas";
IPAddress server_addr(xx, xx ,xx, x);          // MySQL server IP
char user[] = "sitename_user";           // MySQL user
char password[] = "pass";       // MySQL password
void setup () {

Serial.begin(19200);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

 while (conn.connect(server_addr, 3306, user, password) != true) {
    delay(200);
    Serial.println("Connecting SQL..");

  }
      Serial.println("Connected SQL..");


}

void loop() {
 if(Serial.available()>0)    //Checks is there any data in buffer 
  {
    String readx=Serial.readString();
    Serial.print(readx);  //Read serial data byte and send back to serial monitor

if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
//Get the request response payload



HTTPClient http;  //Declare an object of class HTTPClient

http.begin(readx);  //Specify request destination
int httpCode = http.GET();                                                                  //Send the request

if (httpCode > 0) { //Check the returning code

String payload = http.getString(); 
                //Print the response payload

}

http.end();   //Close connection

}
  }

delay(30000);    //Send a request every 30 seconds

}

标签: phpmysqlsqlarduinonodemcu

解决方案


推荐阅读