javascript - JavaScript 可以连接 MySQL 吗?

JavaScript 可以连接 MySQL 吗?如果有,怎么做?

最佳答案

如果没有某种桥接,客户端 JavaScript 无法访问 MySQL。但是上面关于 JavaScript 只是一种客户端语言的粗体陈述是不正确的——JavaScript 可以运行在客户端和服务器端,就像 Node.js 一样。

Node.js 可以通过 https://github.com/sidorares/node-mysql2 之类的方式访问 MySQL

你也可以使用 Socket.IO 开发一些东西

你的意思是问客户端JS应用是否可以访问MySQL?我不确定这样的库是否存在,但它们是可能的。

编辑:自编写以来,我们现在有 MySQL Cluster :

The MySQL Cluster JavaScript Driver for Node.js is just what it sounds like it is – it’s a connector that can be called directly from your JavaScript code to read and write your data. As it accesses the data nodes directly, there is no extra latency from passing through a MySQL Server and need to convert from JavaScript code//objects into SQL operations. If for some reason, you’d prefer it to pass through a MySQL Server (for example if you’re storing tables in InnoDB) then that can be configured.

  • JSDB为数据库提供 JS 接口(interface)。

  • A curated set of DB packages对于来自 sindresorhus 的 Node.js。

https://stackoverflow.com/questions/3020751/

相关文章:

c# - 无法使用 Json 序列化 Web API 中的响应

ruby - 如何以正确的格式写入 JSON 文件

javascript - 在 DOM 中嵌入任意 JSON 的最佳实践?

json - 以友好的方式获取ffmpeg信息

c# - ASP.Net Core 中的 JSON 序列化/反序列化

json - JSON 值是否可以包含多行字符串

javascript - 将数据发布到 JsonP

c# - 如何从 JSON 字符串自动生成 C# 类文件

ruby-on-rails - 将 json 格式的键值对转换为以符号为键的 ruby​​ 哈希的最

python - Python中的字符串到字典