在没有 node.js 的 javascript 服务器端连接到 MySQL

2021-12-13 00:00:00 nginx javascript mysql

我有一个 javascript 应用程序在像 nginxeclipse 本地服务器 这样的服务器上运行,我想知道是否可以将它与 mysql 服务器数据库连接.

I have a javascript application running with server like nginx or eclipse local server, and i would like to know if it is possible to connect it with mysql server database.

我知道它们是 nodejs 应用程序的很多 npm 包,但我不想使用 node js,因为如果我这样做,我有实现具有所有依赖项的 nodejs 应用程序的所有结构,我不太了解这项技术.

I know that they are a lot of npm packages for nodejs application, but i don't want to use node js because if i'll do that i have to implement all structure of nodejs application with all dependencies and i don't know very well this technology to do that.

谢谢.

推荐答案

没有办法直接从浏览器中运行的 JavaScript 连接到远程数据库服务器……如果有的话,可能会涉及一个巨大的安全漏洞,因为任何人有权访问客户端可以获取您的凭据并在服务器上运行他们喜欢的任何 SQL.您不太可能使您的数据库 GRANTS 足够细以供公众使用.

There is no way to connect to a remote database server directly from JavaScript running in a browser… and if there was it would probably involve a huge security hole since anyone with access to the client could take your credentials and run any SQL they like on the server. It is unlikely you could make your database GRANTS fine-grained enough for public consumption.

如果你想让你的客户端 JS 与你的数据库服务器交互,那么你需要为它编写一个 web 服务.您可以在 Node.JS 或您喜欢的任何其他服务器端环境中执行此操作.

If you want your client side JS to interact with your database server then you need to write a webservice for it. You can do that in Node.JS or any other server side environment you like.

如果您使用的是 Node.JS,那么您可能希望 Nginx 代理请求.

If you are using Node.JS then you will probably want Nginx to proxy the requests.

Nginx 支持 FastCGI 所以你可以写任何支持 FastCGI 的语言,例如 Perl 或 PHP.

Nginx supports FastCGI so you could write in any language that supports FastCGI such as Perl or PHP.

相关文章