node js api编码� 串

h9a6wy2h  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(253)

我对这个api有问题。
场地 NAME_CYR 展示� 我不知道怎么解决这个问题?

// Create express app
var express = require("express")
var app = express()
var mysql = require('mysql')
var express = require("express")
var cors = require('cors')

app.use(cors())

// Server port
var HTTP_PORT = 6000

var pool = mysql.createPool({
  connectionLimit: 10,
  host: '192.168.0.10',
  user: 'UName',
  port: '3333',
  password: 'Pass',
  database: 'DBName'
});

var ardaforecast = '';
var stations = '';

app.route('/')
  .get(function (req, res) {
    // omitted
    res.setHeader('Access-Control-Allow-Origin', '*', 'Cache-Control', 'private, no-cache, no-store, must-revalidate');
    const id = req.query.id;

    pool.query(`CALL Get_Alert_levels_Station(${id});`, function (error, result) {
      if (error)
      return res.status(500).json({ error: "Грешна заявка. Опитай отново !"})
      ardaforecast = result;
      res.json({ ardaforecast })
    });
  });

  app.route('/stations')
  .get(function (req, res) {
    // omitted
    res.set({ 'content-type': 'application/json; charset=utf-8' });
    res.setHeader('Access-Control-Allow-Origin', '*', 'Cache-Control', 'private, no-cache, no-store, must-revalidate');

    pool.query(`SELECT * FROM sel_alert_level s;`, function (error, result) {
      if (error)
      return res.status(500).json({ error: "Грешна заявка. Опитай отново !"})
      stations = result;
      res.json({ stations })
    });
  });

// Start server
app.listen(HTTP_PORT, () => {
  console.log("Server running on port %PORT%".replace("%PORT%", HTTP_PORT))
});

pool.on('error', function (err) {
  console.log(err.code); // 'ER_BAD_DB_ERROR'
});

app.use(function (req, res) {
  res.status(404);
});

有没有办法转换这些� 到西里尔语?
当我使用heidisql或mysql工作台时,一切都很好。但是当我在上面写这个查询时 Stations 第页:

SELECT * FROM sel_alert_level s;

田野 NAME_CYR 显示为�..
我正在尝试执行如下查询:

SELECT Map_code, NAME_IME, CONVERT(NAME_CYR USING cp1251), Alertlevelwebsite, CODENUM FROM sel_alert_level s;

但这对我不起作用。有没有办法查看现场数据 NAME_CYR ?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题