在没有node.js的情况下在javascript服务器端连接到MySQL [英] Connect to MySQL in javascript server side without node.js

查看:100
本文介绍了在没有node.js的情况下在javascript服务器端连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像nginxeclipse local server这样的服务器上运行的javascript应用程序,我想知道是否可以将其与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 packages,但是我不想使用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

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

这篇关于在没有node.js的情况下在javascript服务器端连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆