gpt4 book ai didi

javascript - 如何在 Node.JS 上使用 SQL 包检索数据对象?

转载 作者:行者123 更新时间:2023-11-29 09:55:48 25 4
gpt4 key购买 nike

我使用 mysql 从 NodeJS 执行了一个 mysql 查询 npm 包。

成功后,我想读取Javascript中的值。

两者都在同一个域中。

console.log 上,我读到的值为 3

如何检索数据对象值?

var mysql      = require('mysql');
var connection = mysql.createConnection(connectionOptions);

connection.query(
"SELECT * FROM pruebas.Usuarios2 where RFC = '123'",
(err, result, fields) => {
if (result.length) {
// here I need an instruction that can send me the result of 3
// to my javascript console
} else {
console.log('no login');
}
}
);

最佳答案

您不从 Node 发送到 Javascript。您可以使用 Ajax 调用从 Javascript 调用 Node 并返回一个值。

这个问题的答案是如何做到这一点的一个很好的例子: Basic Ajax send/receive with node.js

关于javascript - 如何在 Node.JS 上使用 SQL 包检索数据对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53890034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com