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/